/*
 * Project:		ListenMyStory
 * Purpose:
 * 				[+] Android Publish Book (Image + Text)
 * 				 - Autobiography(UCC, Let me tell you a little something about me)
 * 				 - Novel (General, Game Novel, ...)
 * 				 - Gallery (Pictures + Descriptions)
 * Author:		Ho-Jung Kim (godmode2k@hotmail.com)
 * Date:		Since September 15, 2010
 * Latest modified:	June 09, 2011
 * Filename:	ListenMyStory.java
 * 
 * Source:
 * Note:
 * 		- res/raw/xxx.zip archive is consist of some Pics, Audio and XML file.
 * 		- Pics: p1.jpg, p2, p3, ...
 * 		- Audio: a1.xxx, ...
 * 		- XML: text.xml
 *
 * 		XML for Example)
 * 		<?xml version="1.0" encoding="UTF-8" ?>
 * 		<rss version="2.0">
 * 		<contents>
 * 			<chapter>
 *				<num>1</num>
 * 				<title>Chapter 1</title>
 * 				<pics>p1.jpg</pics>
 * 				<audio>a1.xxx</audio>
 * 				<text>1.txt</text>
 * 			</chapter>
 * 		</contents>
 * 		</rss>
 * ----------------------------------------
 * TODO:
 * 		1. Resource List (Pics, Audio) Management Class [OK]
 * 		2. Move to Previous or Next for change images [OK]
 * 		3. Front page (Cover Image) [OK]
 * 		4. UI Graphic Design
 * 		5. Volume Event [OK]
 * 		6. Loading Image with runOnUiThread [OK]
 * 		7. The relative to all of an image is managed into each chapter [DEPRECATED]
 * 		 - hmm, hmm... hmm... -_-;
 * 		8. Data Structure (xml) {
 * 			1. Bookmark
 * 			2. resource path [OK]
 * 			3. font size [OK]
 * 		}
 * 		9. Menu Dialog {
 * 			1. Bookmark
 * 			2. Audio Volume
 * 			3. Move to the selected page(chapter) [OK] 
 * 			4. Contents List [OK]
 * 			5. Font Size [OK]
 * 			6. Export
 * 			7. Set Resource path [OK]
 * 			8. Load Contents(.zip) from SD card [OK]
 * 			9. Create a contents in the App
 * 			x. ...
 * 		}
 *
 * URGENT!!!
 * TODO:
 * 
 * License:
	This file is part of ListenMyStory.
	ListenMyStory is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.
	
	ListenMyStory is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License
	along with ListenMyStory.  If not, see <http://www.gnu.org/licenses/>.
*/

package com.JustListen.ListenMyStory;

import android.app.Activity;
import android.app.PendingIntent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.StatFs;
import android.os.Vibrator;
import android.util.Log;

// -------------------------------------------
// File I/O
//
// Reference:
// 	http://developer.android.com/reference/java/util/zip/ZipEntry.html
// 	http://developer.android.com/reference/java/util/zip/ZipOutputStream.html
//	-----
// 	http://www.netmite.com/android/mydroid/dalvik/libcore/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipEntryTest.java
// 	http://www.jondev.net/articles/Zipping_Files_with_Android_%28Programmatically%29
//-------------------------------------------
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.AssetFileDescriptor;
import android.content.res.Configuration;

//-------------------------------------------
// Graphics
//-------------------------------------------
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

//-------------------------------------------
// Media Player
//-------------------------------------------
import android.media.AudioManager;
import android.media.MediaPlayer;

//-------------------------------------------
// Widget
//-------------------------------------------
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

//-------------------------------------------
// Layout
//-------------------------------------------
//Screen On/Off
import android.view.HapticFeedbackConstants;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SurfaceHolder;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

//-------------------------------------------
// Dialog
//-------------------------------------------
import android.app.Dialog;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;

//-------------------------------------------
// Indicator / Notification
//-------------------------------------------
import android.app.*;
//import android.content.pm.ActivityInfo;
import android.widget.RemoteViews;
import android.widget.AdapterView.OnItemClickListener;

//-------------------------------------------
// XML
//-------------------------------------------
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import java.util.Iterator;
// URL
import java.net.URL;
import java.net.URLConnection;



public class ListenMyStory extends Activity {
	private static final String TAG = "ListenMyStory";
	private static final boolean m_isDebugOn = true;
	private ListenMyStoryApp m_MainApp = null;
	
	// -----------------------------
	// Zip File System
	// -----------------------------
	private AssetFileDescriptor m_LIR_afd = null;
	private InputStream m_LIR_is = null;
	private OutputStream m_LIR_os = null;
	private ZipInputStream m_LIR_zIS = null;
	private ZipOutputStream m_LIR_zOS = null;
	//private BufferedOutputStream m_LIR_bOS = null;
	private ByteArrayOutputStream m_LIR_baOS = null;
	private int m_currentImagePosition = -1;	// -1: NO RESOURCE LOADED
	
	// -----------------------------
	// Orientation (Portrait, Landscape)
	// -----------------------------
	private boolean m_isFullScreen = false;
	
	// -----------------------------
	// Indicator / Notification
	// -----------------------------
	private NotificationManager mNM = null;
	
	// -----------------------------
	// Export
	// -----------------------------
	private boolean m_isSelectExternalStorage = false;
	private boolean m_isAnErrorToExport = false;
	
	// -----------------------------
	// Resource
	// -----------------------------
	private final int m_ResPackage = R.raw.respkg;
	private final String m_ResPackageXml = "text";
	private File m_TmpFile = null;	// text.xml
	private xmlResManage m_xmlResManage = new xmlResManage();
	private List<xmlResManage> m_xmlResList = new ArrayList<xmlResManage>();
	/*
	private class CResZip {
		private int m_index = -1;
		private ZipEntry m_zEntry = null;
		
		public CResZip(int index, ZipEntry zEntry) {
			m_index = index;
			m_zEntry = (ZipEntry)zEntry.clone();
		}
		public boolean SetZipEntry(ZipEntry zEntry) {
			if( m_zEntry != null )
				m_zEntry = null;

			m_zEntry = (ZipEntry)zEntry.clone();
			return (m_zEntry != null);
		}
		public int GetIndex() {
			return m_index;
		}
	}
	private ArrayList<CResZip> m_arrayResList = new ArrayList<CResZip>();
	*/
	
	// -----------------------------
	// Haptic
	// -----------------------------
	Vibrator m_Vibrator = null;
	
	// -----------------------------
	// Media
	// -----------------------------
	AudioManager m_AudioManager = null;
	int m_CurrentVolume = 0;
	boolean m_Mute = false;

	// -----------------------------
	// Thread & Loading Animation
	// -----------------------------
    ProgressDialog _ProgressDlg_AttachLoadingAni_ = null;
    private static final int __RUN_THREAD__LOAD_RESOURCE__ = 0;
    private static final int __RUN_THREAD__LOAD_TEST1__ = 1;
    private static final int __RUN_THREAD__LOAD_TEST2__ = 2;

	// -----------------------------
	// Option & Context Menu
	// -----------------------------
    private Menu m_Menu = null;
    private boolean m_Menu_flag__2_ = false;	// true/false: Text only or with Picture
    private boolean m_Menu_flag__3_ = true;		// true/false: Font size zoom(prefixed) in or out
    // Move to page
	private static final int __MAIN_OPTION_MENU__1__ = 0;
	// Text Only or With Picture
	private static final int __MAIN_OPTION_MENU__2__ = 1;
	// Font Size
	private static final int __MAIN_OPTION_MENU__3__ = 2;
	// Load a resource
	private static final int __MAIN_OPTION_MENU__4__ = 3;
	// Preference
	private static final int __MAIN_OPTION_MENU__5__ = 4;

	// -----------------------------
	// Contents List ListView
	// -----------------------------
	private ListView m_ListViewResContents = null;
	private SimpleAdapter m_ListViewResContentsAdapter = null;



    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        __DEBUG__( "onCreate()" );

        setContentView( R.layout.main );

        // Get Main Class of the Application
        m_MainApp = (ListenMyStoryApp)getApplicationContext();

        // Haptic
        m_Vibrator = (Vibrator)this.getSystemService( VIBRATOR_SERVICE );

        // Indicator / Notification
        //showNotification();

        // Force Screen On
        getWindow().addFlags( WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON );

        // -----

        // Initialize
        InitAll();

// FIXME: USE the Thread
// {*****
        // Load a resource into APK
//        LoadContentsFromResource();

        // Load a resource from SD card
        //LoadFromResourceOfSDcard( true, "test.zip" );	// for TEST (fill the filename without path)
        //LoadContentsFromSDcard( "test.zip" );
// *****}

        // -----

		// Test
		/*
        TEST_ZipArchive();
		TEST_GetContent();
		TEST_XML_Array();
		*/
		/*
		{
			try {
				FileOutputStream f = openFileOutput( "my_file.txt", MODE_WORLD_READABLE );
				f.write( "test".getBytes() );
				f.close();
				deleteFile( "my_file.txt" );
			} catch (IOException e) {
				// TODO Auto-generated catch block
				//e.printStackTrace();
				__DEBUG__( "onCreate(): IOException: " + e.getMessage() );
			}
		}
		*/
    }

    @Override
    protected void onDestroy() {
    	super.onDestroy();
    	
        __DEBUG__( "onDestroy()" );
    	
        // Resource this APK's
        ReleaseLoadInternalResource( true );

        // XML Management
        if( m_xmlResList != null ) {
        	m_xmlResList.clear();
        	m_xmlResList = null;
        }
		if( m_xmlResManage != null )
			m_xmlResManage = null;

		// Clean up All for Application
		m_MainApp.CLEAN_UP_ALL();
    }

    /*
     * Activity Status
		run1: app
			onStart -> onResume
		
		run2-1: app -> no play -> home
			onSaveInstanceState -> onStop
		run2-2: app
			onStop -> onRestart -> onStart -> onResume
		
		run3-1: play -> home
			onSaveInstanceState -> onStop
		run3-2: app
			onRestart -> onStart -> onResume
    */

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        // TODO Auto-generated method stub
        //super.onConfigurationChanged(newConfig);
        
        __DEBUG__( "onConfigurationChanged()" );
        
        if( m_isFullScreen ) {
        	__DEBUG__( "Orientation: Full Screen -> restore" );
        	m_isFullScreen = false;
        	//getWindow().setFlags( WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR, WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR );
        	//setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_PORTRAIT );
        	getWindow().clearFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN );
        }
        else {
        	__DEBUG__( "Orientation: Full Screen" );
        	m_isFullScreen = true;
        	getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN );
        }
        
        super.onConfigurationChanged( newConfig );
    }
    
    public void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        
        __DEBUG__( "onRestoreInstanceState()" );
    }

    public void onRestart(){
        super.onRestart();

        __DEBUG__( "onRestart()" );
    }

    public void onStart(){
        super.onStart();
        
        __DEBUG__( "onStart()" );
    }
   
    public void onResume(){
        super.onResume();
        
        __DEBUG__( "onResume()" );
        
    	//Intent i = new Intent( "com.android.music.musicservicecommand" );
    	//i.putExtra( "command", "pause" );
    	////i.putExtra( "_ListenMyStory_", "_ListenMyStory_" );
    	//sendBroadcast( i );
        
        if( m_MainApp != null ) {
        	//m_MainApp.GetConfManager()
        }
    }
    
    public void onSaveInstanceState(Bundle savedInstanceState){
        super.onSaveInstanceState(savedInstanceState);
        
        __DEBUG__( "onSaveInstanceState()" );
    }
    
    public void onPuase() {
        super.onPause();

        __DEBUG__( "onPuase()" );
    }

    public void onStop() {
        super.onStop();

        __DEBUG__( "onStop()" );
    }
    
    // Create the Menu Items
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    	boolean ret = super.onCreateOptionsMenu( menu );

    	menu.add( 0, __MAIN_OPTION_MENU__1__, 0, getResources().getText(R.string.MAIN_MENU_1) );
		menu.add( 0, __MAIN_OPTION_MENU__2__, 0, getResources().getText(R.string.MAIN_MENU_2A) );
    	menu.add( 0, __MAIN_OPTION_MENU__3__, 0, getResources().getText(R.string.MAIN_MENU_3A) );
    	menu.add( 0, __MAIN_OPTION_MENU__4__, 0, getResources().getText(R.string.MAIN_MENU_4) );
    	menu.add( 0, __MAIN_OPTION_MENU__5__, 0, getResources().getText(R.string.MAIN_MENU_5) );

    	// Move to page
    	menu.getItem(__MAIN_OPTION_MENU__1__).setIcon( R.drawable.ic_menu_directions );
    	// Text Only or With Picture
    	menu.getItem(__MAIN_OPTION_MENU__2__).setIcon( R.drawable.ic_menu_report_image );
    	// Font Size
    	menu.getItem(__MAIN_OPTION_MENU__3__).setIcon( R.drawable.ic_menu_zoom );
    	// Load a resource
    	menu.getItem(__MAIN_OPTION_MENU__4__).setIcon( R.drawable.ic_menu_archive );
    	// Preference
    	menu.getItem(__MAIN_OPTION_MENU__5__).setIcon( R.drawable.ic_menu_preferences );
    	
    	m_Menu = menu;

    	return ret;
    }
    
    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
    	// TODO Auto-generated method stub
    	//return super.onPrepareOptionsMenu(menu);

    	// Set Menu State
    	//if( !GetPrepare() ) {
    	if( GetCurrentPosition() < 0 ) {
    		// Set disable menu
    		// Move to page
        	menu.getItem(__MAIN_OPTION_MENU__1__).setEnabled( false );
        	// Text Only or With Picture
        	menu.getItem(__MAIN_OPTION_MENU__2__).setEnabled( false );
        	// Font Size
        	menu.getItem(__MAIN_OPTION_MENU__3__).setEnabled( false );
        	// Load a resource
        	//menu.getItem(__MAIN_OPTION_MENU__4__).setEnabled( false );
        	// Preference
        	//menu.getItem(__MAIN_OPTION_MENU__5__).setEnabled( false );

    		return super.onPrepareOptionsMenu( menu );
    	}

    	// Set enable menu
    	// Move to page
    	menu.getItem(__MAIN_OPTION_MENU__1__).setEnabled( true );
    	// Text Only or With Picture
    	menu.getItem(__MAIN_OPTION_MENU__2__).setEnabled( true );
    	// Font Size
    	menu.getItem(__MAIN_OPTION_MENU__3__).setEnabled( true );
    	// Load a resource
    	menu.getItem(__MAIN_OPTION_MENU__4__).setEnabled( true );
    	// Preference
    	menu.getItem(__MAIN_OPTION_MENU__5__).setEnabled( true );

    	
    	// Text Only or With Picture
    	{
			ImageView iv = null;
			iv = (ImageView)findViewById( R.id.ImageView_Pics );
			if( iv != null ) {
				if( m_Menu_flag__2_ ) {
				//if( iv.getVisibility() == View.VISIBLE ) {
					iv.setVisibility( View.GONE );
					menu.getItem(__MAIN_OPTION_MENU__2__).setTitle( getResources().getText(R.string.MAIN_MENU_2B) );
					// Text Only or With Picture
					menu.getItem(__MAIN_OPTION_MENU__2__).setIcon( R.drawable.ic_menu_slideshow );
				}
				else {
					//GetContentCurrently();
					iv.setVisibility( View.VISIBLE );
					menu.getItem(__MAIN_OPTION_MENU__2__).setTitle( getResources().getText(R.string.MAIN_MENU_2A) );
					// Text Only or With Picture
					menu.getItem(__MAIN_OPTION_MENU__2__).setIcon( R.drawable.ic_menu_report_image );
				}
			}
    	}
    	
    	// Font Size
    	{
    		TextView tv = (TextView)findViewById( R.id.TextView_Text );
			if( tv != null ) {
				//Log.d( TAG, ">>> " + tv.getTextSize() );

				// Normal(Default) Font Size: 21.0sp (Comparison only)
				// - but it's wrong value as i see. so USE 14.0sp
				if( m_Menu_flag__3_ ) {
				//if( tv.getTextSize() > 21.0 ) {	// In Emulator: USE ">= 21.0"
					//tv.setTextSize( 14.0f );
					menu.getItem(__MAIN_OPTION_MENU__3__).setTitle( getResources().getText(R.string.MAIN_MENU_3A) );
				}
				// Normal Large Font Size: 21.0sp
				else {
					//tv.setTextSize( 21.0f );
					
					//tv.setTextSize( (float)Integer.parseInt(m_MainApp.GetConfManager().GetFontSize()) );
					menu.getItem(__MAIN_OPTION_MENU__3__).setTitle( getResources().getText(R.string.MAIN_MENU_3B) );
				}
			}
    	}
    	
    	return super.onPrepareOptionsMenu(menu);
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    	switch( item.getItemId() ) {
	    	case __MAIN_OPTION_MENU__1__:
	    		// Move to page
	    		__DEBUG__( "onOptionsItemSelected(): selected __MAIN_OPTION_MENU__1__" );

				{
					String strTitle = "" + getResources().getText( R.string.app_name );
					String str = "List of Contents";
					DlgContentsList( strTitle, str );
				}
	    		return true;
	    	case __MAIN_OPTION_MENU__2__:
	    		// Text Only or With Picture
		    	__DEBUG__( "onOptionsItemSelected(): selected __MAIN_OPTION_MENU__2__" );

		    	{	
		    		ImageView iv = null;
		    		iv = (ImageView)findViewById( R.id.ImageView_Pics );
		    		if( iv != null ) {
		    			if( iv.getVisibility() == View.VISIBLE ) {
		    				m_Menu_flag__2_ = true;
		    				iv.setVisibility( View.GONE );
		    				//item.setTitle( getResources().getText(R.string.MAIN_MENU_2B) );
		    				// Text Only or With Picture
		    				//item.setIcon( R.drawable.ic_menu_slideshow );
		    			}
		    			else {
		    				m_Menu_flag__2_ = false;
		    				GetContentCurrently();
		    				iv.setVisibility( View.VISIBLE );
		    				//item.setTitle( getResources().getText(R.string.MAIN_MENU_2A) );
		    				// Text Only or With Picture
		    				//item.setIcon( R.drawable.ic_menu_report_image );
		    			}
		    		}
	    		}
	    		return true;
	    	case __MAIN_OPTION_MENU__3__:
	    		// Font Size
	    		// - Emulator (320x480): Default size is 14.0sp
	    		// - Device (Nexus One 480x800): Default size is 21.0sp (I don't believe it -_-; so, USE 14.0sp)
	    		__DEBUG__( "onOptionsItemSelected(): selected __MAIN_OPTION_MENU__3__" );

	    		{
	    			TextView tv = (TextView)findViewById( R.id.TextView_Text );
	    			if( tv != null ) {
	    				Log.d( TAG, ">>> " + tv.getTextSize() );
	    				// Normal(Default) Font Size: 21.0sp (Comparison only)
	    				// - but it's wrong value as i see. so USE 14.0sp
	    				if( tv.getTextSize() > 21.0 ) {	// In Emulator: USE ">= 21.0"
	    					m_Menu_flag__3_ = true;
	    					tv.setTextSize( 14.0f );
	    					//item.setTitle( getResources().getText(R.string.MAIN_MENU_3A) );
	    				}
	    				// Normal Large Font Size: 21.0sp
	    				else {
	    					//tv.setTextSize( 21.0f );
	    					
	    					m_Menu_flag__3_ = false;
	    					tv.setTextSize( (float)Integer.parseInt(m_MainApp.GetConfManager().GetFontSize()) );
	    					//item.setTitle( getResources().getText(R.string.MAIN_MENU_3B) );
	    				}
	    			}
	    		}
	    		return true;
	    	case __MAIN_OPTION_MENU__4__:
	    		// Load a resource from External Storage(SD card)
	    		__DEBUG__( "onOptionsItemSelected(): selected __MAIN_OPTION_MENU__4__" );
///*
	    		{
	    			String strTitle = "" + getResources().getText( R.string.app_name );
					String str = "";
	    			DlgSDcardResourceList( strTitle, str );
	    		}
//*/
	    		//Toast.makeText( ListenMyStory.this, "[Professional Edition Only]", Toast.LENGTH_LONG ).show();
	    		return true;
	    	case __MAIN_OPTION_MENU__5__:
	    		// Preference
	    		__DEBUG__( "onOptionsItemSelected(): selected __MAIN_OPTION_MENU__5__" );

	    		{
		    		Intent intt = null;
		    		intt = new Intent( ListenMyStory.this, AppPreferenceActivity.class );
		    		if( intt != null )
		    			startActivity( intt );
	    		}
	    		return true;
    	}
    	
    	return false;
    }

    @Override
    protected Dialog onCreateDialog(int id) {
    	// TODO Auto-generated method stub
    	//return super.onCreateDialog(id);
    	
    	switch( id ) {
	    	default:
	    		break;
    	}
    	
    	return super.onCreateDialog(id);
    }
    
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
    	if( keyCode == KeyEvent.KEYCODE_BACK ) {
    		// ...
    	}
    	else if( keyCode == KeyEvent.KEYCODE_MENU ) {
    		// ...
    	}
    	else {
    		AudioManager am = null;
    		am = (AudioManager)getSystemService( AUDIO_SERVICE );
    		if( am == null )
    			return super.onKeyDown( keyCode, event );

	    	switch( keyCode ) {
	    		case KeyEvent.KEYCODE_VOLUME_UP:
	    			am.adjustStreamVolume( AudioManager.STREAM_MUSIC,
	    					AudioManager.ADJUST_RAISE,
	    					AudioManager.FLAG_SHOW_UI );
	    			break;
	    		case KeyEvent.KEYCODE_VOLUME_DOWN:
	    			am.adjustStreamVolume( AudioManager.STREAM_MUSIC,
	    					AudioManager.ADJUST_LOWER,
	    					AudioManager.FLAG_SHOW_UI );
	    			break;
	    	}
	    	
	    	m_CurrentVolume = m_AudioManager.getStreamVolume( AudioManager.STREAM_MUSIC );
	    	m_AudioManager.setStreamVolume( AudioManager.STREAM_MUSIC, m_CurrentVolume, 0 );
	    	if( m_CurrentVolume == 0 )
	    		m_Mute = true;
	    	else
	    		m_Mute = false;
	    	
	    	return true;
    	}

    	return super.onKeyDown( keyCode, event );
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
    	if( keyCode == KeyEvent.KEYCODE_BACK ) {
    		// ...
    	}
    	else if( keyCode == KeyEvent.KEYCODE_MENU ) {
    		// ...
    	}
    	else {
    		AudioManager am = null;
    		am = (AudioManager)getSystemService( AUDIO_SERVICE );
    		if( am == null )
    			return super.onKeyUp( keyCode, event );

	    	switch( keyCode ) {
	    		case KeyEvent.KEYCODE_VOLUME_UP:
	    			am.adjustStreamVolume(AudioManager.STREAM_MUSIC, 
	    					AudioManager.ADJUST_SAME, 
	    					AudioManager.FLAG_SHOW_UI);
	    			break;
	    		case KeyEvent.KEYCODE_VOLUME_DOWN:
	    			am.adjustStreamVolume(AudioManager.STREAM_MUSIC, 
	    					AudioManager.ADJUST_SAME, 
	    					AudioManager.FLAG_SHOW_UI);
	    			break;
	    	}
	    	
	    	m_CurrentVolume = m_AudioManager.getStreamVolume( AudioManager.STREAM_MUSIC );
	    	m_AudioManager.setStreamVolume( AudioManager.STREAM_MUSIC, m_CurrentVolume, 0 );
	    	if( m_CurrentVolume == 0 )
	    		m_Mute = true;
	    	else
	    		m_Mute = false;
	    	
	    	return true;
    	}

    	return super.onKeyUp( keyCode, event );
    }
    
    public void __DEBUG__(String str) {
    	if( m_isDebugOn )
    		Log.d( TAG, str );
    }

    public void __DEBUG_ERROR__(String str) {
   		Log.d( TAG, str );
    }

// -------------------------------------------
// Thread
// -------------------------------------------
    private void __ATTACH_LOADING_ANI__(boolean attach, String strTitle) {
    	__DEBUG__( "__ATTACH_LOADING_ANI(): " + attach );

    	if( _ProgressDlg_AttachLoadingAni_ != null ) {
	    	if( attach ) {
	    		_ProgressDlg_AttachLoadingAni_ = ProgressDialog.show( ListenMyStory.this, strTitle, "Loading, Please wait...", true );
	    		__DEBUG__( "__ATTACH_LOADING_ANI(): Attached" );
	    	}
	    	else {
	    		_ProgressDlg_AttachLoadingAni_.dismiss();
	    		__DEBUG__( "__ATTACH_LOADING_ANI(): Detached" );
	    	}
    	}
    }

    public void __RUN_THREAD__(int type, String strTitle) {
    	__DEBUG__( "__RUN_THREAD__()" );
    	
    	__ATTACH_LOADING_ANI__( true, strTitle );

    	switch( type ) {
	    	case __RUN_THREAD__LOAD_RESOURCE__:
	    		break;
	    	case __RUN_THREAD__LOAD_TEST1__:
	    		break;
	    	case __RUN_THREAD__LOAD_TEST2__:
	    		break;
    	}
    }

    private void thread_LoadResource(final String strTitle) {
    	__DEBUG__( "thread_LoadResource()" );
    	
    	boolean escape = false;
    	
    	// ...
    	// ...
    	
    	runOnUiThread( new Runnable() {
			@Override
			public void run() {
				// TODO Auto-generated method stub
				
					// ...
					__ATTACH_LOADING_ANI__( false, strTitle );
			}
		});
    	
    	
    	// ----------

// NOTE
/*
    	new Thread( new Runnable() {
    		@Override
			public void run() {
    	    	runOnUiThread( new Runnable() {
    				@Override
    				public void run() {
    					// TODO Auto-generated method stub
    					
    						// ...
    						__ATTACH_LOADING_ANI__( false );
    				}
    			});
			}
		});
*/
    }
   
    private void thread_LoadTest1(final String strTitle) {
    	__DEBUG__( "thread_LoadTest1()" );
    	
    	boolean escape = false;
    	
    	// ...
    	// ...
    	
    	runOnUiThread( new Runnable() {
			@Override
			public void run() {
				// TODO Auto-generated method stub
				
					// ...
					__ATTACH_LOADING_ANI__( false, strTitle );
			}
		});
    }

    private void thread_LoadTest2(final String strTitle) {
    	__DEBUG__( "thread_LoadTest2()" );
    	
    	boolean escape = false;
    	
    	// ...
    	// ...
    	
    	runOnUiThread( new Runnable() {
			@Override
			public void run() {
				// TODO Auto-generated method stub
				
					// ...
					__ATTACH_LOADING_ANI__( false, strTitle );
			}
		});
    }


// -------------------------------------------
// Initialize
// Layout, Event, Handler, ...
// -------------------------------------------
    public void InitAll() {
    	ImageButton img_btn_Home = (ImageButton)findViewById( R.id.ImageButton_Home );
    	ImageButton btn_Prev = (ImageButton)findViewById( R.id.Button_Prev );
    	ImageButton btn_Next = (ImageButton)findViewById( R.id.Button_Next );
    	//ImageButton img_btn_Menu = (ImageButton)findViewById( R.id.ImageButton_Menu );

    	__DEBUG__( "InitAll()" );

    	View.OnClickListener btn_Home_Listener = ( new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					__DEBUG__( "InitAll(): View.OnClickListener(): onClick(): HOME" );
					//Toast.makeText( ListenMyStory.this, "Button: HOME", Toast.LENGTH_SHORT ).show();
					m_Vibrator.vibrate( 20 );
					
					if( GetCurrentPosition() < 0 ) {
						__DEBUG__( "InitAll(): View.OnClickListener(): onClick(): HOME: NO RESOURCE LOADED" );
						return;
					}
	
					m_currentImagePosition = 0;
					
					{
						ImageButton btn_next = (ImageButton)findViewById(R.id.Button_Next );
						ImageButton btn_prev = (ImageButton)findViewById(R.id.Button_Prev );

						if( btn_next != null )
							btn_next.setBackgroundResource( R.drawable.btn_arrow_next_thick );

						if( btn_prev != null )
							btn_prev.setBackgroundResource( R.drawable.btn_arrow_prev_empty );
					}

					// Set first page
					LoadFromResourceOfThisAPK( false, true );
					GetContentInit();
/*
					if( m_MainApp != null ) {
						String strLastFile = "";
						strLastFile = m_MainApp.GetConfManager().GetLastFile();
						if( !strLastFile.equals("") ) {
							LoadContentsFromSDcard( strLastFile );
							GetContentInit();
						}
					}
*/
					if( m_xmlResList != null && !m_xmlResList.isEmpty() ) {
						if( m_xmlResManage != null ) {
							if( m_xmlResManage != null ) {
								xmlResManage xmlEntry = m_xmlResList.get( 0 );

								if( xmlEntry != null ) {
									TextView tv_title = (TextView)findViewById( R.id.TextView_Title );
									TextView tv_text = (TextView)findViewById( R.id.TextView_Text );
									TextView tv_textPosition = (TextView)findViewById( R.id.TextView_Position );
									
									if( tv_title != null )
										tv_title.setText( xmlEntry.GetTitle() );

									//if( tv_text != null )
									//	tv_text.setText( xmlEntry.GetText() );

									if( tv_textPosition != null ) {
										String str = "(" + Integer.toString(GetCurrentPosition()) + "/" + Integer.toString(XML_GetEntryCount()) + ")";
										tv_textPosition.setText( str );
									}
								}
							}
						}
					}
					else {
						__DEBUG_ERROR__( "InitAll(): Could not init first content" );
			        	Toast.makeText( ListenMyStory.this, "Could not init first content", Toast.LENGTH_SHORT ).show();
					}
				}
			}
		);
		img_btn_Home.setOnClickListener( btn_Home_Listener );

    	View.OnClickListener btn_Prev_Listener = ( new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					__DEBUG__( "InitAll(): View.OnClickListener(): onClick(): PREV" );
					//Toast.makeText( ListenMyStory.this, "Button: PREV", Toast.LENGTH_SHORT ).show();
					m_Vibrator.vibrate( 20 );

					if( GetCurrentPosition() < 0 ) {
						__DEBUG__( "InitAll(): View.OnClickListener(): onClick(): PREV: NO RESOURCE LOADED" );
						return;
					}

					GetContentPrevious();
				}
			}
    	);
    	btn_Prev.setOnClickListener( btn_Prev_Listener );

    	View.OnClickListener btn_Next_Listener = ( new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					__DEBUG__( "InitAll(): View.OnClickListener(): onClick(): NEXT" );
					//Toast.makeText( ListenMyStory.this, "Button: NEXT", Toast.LENGTH_SHORT ).show();
					m_Vibrator.vibrate( 20 );
					
					if( GetCurrentPosition() < 0 ) {
						__DEBUG__( "InitAll(): View.OnClickListener(): onClick(): NEXT: NO RESOURCE LOADED" );
						return;
					}

					//GetContent();
					GetContentNext();
				}
			}
		);
		btn_Next.setOnClickListener( btn_Next_Listener );

		/*
    	View.OnClickListener btn_Menu_Listener = ( new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					__DEBUG__( "InitAll(): View.OnClickListener(): onClick(): MENU" );
					//Toast.makeText( ListenMyStory.this, "Button: MENU", Toast.LENGTH_SHORT ).show();
					m_Vibrator.vibrate( 20 );
					
					Intent intt_appPreference = new Intent( ListenMyStory.this, AppPreferenceActivity.class );
					startActivity( intt_appPreference );
				}
			}
		);
		img_btn_Menu.setOnClickListener( btn_Menu_Listener );
		*/
		
		// Volume
		m_AudioManager = (AudioManager)getSystemService( AUDIO_SERVICE );
		int vol_max = m_AudioManager.getStreamMaxVolume( AudioManager.STREAM_MUSIC );
		m_CurrentVolume = m_AudioManager.getStreamVolume( AudioManager.STREAM_MUSIC );
		//m_AudioManager.setStreamVolume( AudioManager.STREAM_MUSIC, m_CurrentVolume, 0 );
		
		// Load a configuration
		if( m_MainApp != null ) {
			m_MainApp.GetLoadConf();
		}
    }
    
    // Change Control Menu Position to LHS or RHS
    public void ChangeUI_LeftHandsSide(boolean lhs) {
    	__DEBUG__( "ChangeUI_HandsSide()" );
    	
    	if( lhs ) {
    		__DEBUG__( "ChangeUI_HandsSide(): Change to LHS" );
    		android.widget.RelativeLayout rl = (android.widget.RelativeLayout)findViewById( R.id.RelativeLayout_LHS );
    		if( rl != null ) {
    			if( rl.getVisibility() != View.VISIBLE )
    				rl.setVisibility( View.VISIBLE );
    		}
    	}
    	else {
    		__DEBUG__( "ChangeUI_HandsSide(): Change to RHS" );
    		android.widget.RelativeLayout rl = (android.widget.RelativeLayout)findViewById( R.id.RelativeLayout_RHS );
    		if( rl != null ) {
    			if( rl.getVisibility() != View.VISIBLE )
    				rl.setVisibility( View.VISIBLE );
    		}
    	}
    }

// -------------------------------------------
// Indicator / Notification
// Show a notification while this service is running.
// -------------------------------------------
    public void RemoveNotification() {
    	__DEBUG__( "RemoveNotification()" );

        // Indicator: Notification
		if( mNM != null ) {
	    	//mNM.cancel( R.string.app_name );
	        // Use custom view
			mNM.cancel( R.layout.notification );
		}
    }
    
    public void ShowNotification() {
    	__DEBUG__( "ShowNotification()" );

    	RemoveNotification();
    	mNM = (NotificationManager)getSystemService( NOTIFICATION_SERVICE );

        // In this sample, we'll use the same text for the ticker and the expanded notification
        //CharSequence text = getText( R.string.remote_service_started );
    	CharSequence text = getText( R.string.app_name );

        // Set the icon, scrolling text and timestamp
        //Notification notification = new Notification(R.drawable.stat_sample, text,
        //Notification notification = new Notification( -1, text,
    	Notification notification = new Notification( R.drawable.cover, text,
                System.currentTimeMillis() );

        // Set Intent
        Intent intent = new Intent( this,  ListenMyStory.class );
        intent.setFlags( Intent.FLAG_ACTIVITY_SINGLE_TOP );
        
        // Set custom view
        RemoteViews contentView = new RemoteViews( getPackageName(), R.layout.notification );
        ////contentView.setImageViewResource( R.id.image, R.drawable.notification_image );
        ////contentView.setTextViewText( R.id.text, "Hello, this message is in a custom expanded view" );
        //contentView.setImageViewResource( R.id.image, R.drawable.cover );
        contentView.setTextViewText( R.id.TextViewIndicator, getText(R.string.app_name) ); 
        notification.contentView = contentView;

        // The PendingIntent to launch our activity if the user selects this notification
        PendingIntent contentIntent = PendingIntent.getActivity( this, 0,
                //new Intent(this,  ListenMyStory.class), 0 );
        		intent, 0 );
        
        // Use custom view
        notification.contentIntent = contentIntent;

        // Set the info for the views that show in the notification panel.
        //notification.setLatestEventInfo(this, getText(R.string.local_service_label),
        //notification.setLatestEventInfo( this, getText(R.string.mediaTitle),
        //               text, contentIntent );
        
        // Send the notification.
        // We use a string id because it is a unique number.  We use it later to cancel.
        //mNM.notify( R.string.remote_service_started, notification );
        //mNM.notify( R.string.app_name, notification );
        
        // Use custom view
        mNM.notify( R.layout.notification, notification );
    }

// -------------------------------------------
// Show Control Panel
// -------------------------------------------
/*
    private boolean ShowControlPanel(boolean isRunnable) {
    	__DEBUG__( "ShowControlPanel()" );

    	boolean ret = true;
		android.widget.LinearLayout rl = (android.widget.LinearLayout)findViewById( R.id.LinearLayoutControlPanel );
		if( rl.getVisibility() != rl.VISIBLE ) {
			if( isRunnable )
				return false;

	    	rl.setVisibility( 0 );
	    	ret = true;
	    	
	    	__DEBUG__( "ShowControlPanel(): Set Visibility to Show" );
		}
		else {
	    	rl.setVisibility( 4 );
	    	ret = false;
	    	__DEBUG__( "ShowControlPanel(): Set Visibility to Hidden" );
		}
	    //rl.invalidate();
		
		return ret;
    }
*/

// -------------------------------------------
// SurfaceHolder
// -------------------------------------------
    private void surfaceChanged(SurfaceHolder surfaceholder, int format, int width, int height) {
    	// ...
    	__DEBUG__( "surfaceChanged()" );
    }

    private void surfaceDestroyed(SurfaceHolder surfaceholder) {
    	// ...
    	__DEBUG__( "surfaceDestroyed()" );
    }

    private void surfaceCreated(SurfaceHolder holder) {
    	// ...
    	__DEBUG__( "surfaceCreated()" );

    	/*
    	MediaPlayer.pause();
   		SurfaceHolder = holder;
   		MediaPlayer.setDisplay( holder );
   		MediaPlayer.prepare();
    	//MediaPlayer.start();
    	*/
    }

// ---------------------------------------------
// Dialog Message Box
// ---------------------------------------------

    public void DlgFail(String strTitle, String strMessage) {
		final Builder winAlert;
		Dialog winDialog;
    	LayoutInflater li = LayoutInflater.from( this );
    	View viewDlgFail = li.inflate( R.layout.dlg_messagebox, null );
    	
    	__DEBUG__( "DlgFail()" );    	

    	// Back Key
    	DialogInterface.OnKeyListener keyListener = new DialogInterface.OnKeyListener() {
			@Override
			public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
				// TODO Auto-generated method stub
				
				if( keyCode == KeyEvent.KEYCODE_BACK )
					return true;

				return false;
			}
		};

    	DialogInterface.OnClickListener okListener = new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				
				// OK
				if( which == -1 ) {
					__DEBUG__( "DlgFail(): Button: SELECTED #1 OK" );
					//Toast.makeText( ListenMyStory.this, "...", Toast.LENGTH_SHORT ).show();
				}
				// Cancel #1
				else if( which == -3 ) {
					__DEBUG__( "DlgFail(): Button: SELECTED #2 Cancel" );
				}
				// Cancel #2
				else if( which == -2 ) {
					__DEBUG__( "DlgFail(): Button: SELECTED #3 (Cancel)" );				
				}				
				
				dialog.cancel();
				
				__DEBUG__( "DlgFail(): Finish: =====Exit App=====" );
				System.exit( 1 );
				return;
			}
		};
		
		winAlert = new AlertDialog.Builder( this )
			.setIcon( R.drawable.icon )
			.setOnKeyListener( keyListener )
			//.setTitle( getResources().getString(R.string.dlgFailTitle) )
			//.setMessage( ListenMyStory.this.m_strResMsg )
			.setTitle( strTitle )
			.setMessage( strMessage )
			.setPositiveButton( getResources().getString(R.string.dlgBtn_OK), okListener )
			.setView( viewDlgFail );
		winDialog = winAlert.create();
		winDialog.show();
    }

    public void DlgMessageBox(String strTitle, String strMessage) {
		final Builder winAlert;
		Dialog winDialog;
    	LayoutInflater li = LayoutInflater.from( this );
    	View viewDlgMessageBox = li.inflate( R.layout.dlg_messagebox, null );
    	
    	__DEBUG__( "DlgMessageBox()" );    	

    	// Back Key
    	DialogInterface.OnKeyListener keyListener = new DialogInterface.OnKeyListener() {
			@Override
			public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
				// TODO Auto-generated method stub
				
				if( keyCode == KeyEvent.KEYCODE_BACK )
					return true;

				return false;
			}
		};
    	
    	DialogInterface.OnClickListener okListener = new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				
				// OK
				if( which == -1 ) {
					__DEBUG__( "DlgMessageBox(): Button: SELECTED #1 OK" );
					//Toast.makeText( ListenMyStory.this, "...", Toast.LENGTH_SHORT ).show();
				}
				// Cancel #1
				else if( which == -3 ) {
					__DEBUG__( "DlgMessageBox(): Button: SELECTED #2 Cancel" );
				}
				// Cancel #2
				else if( which == -2 ) {
					__DEBUG__( "DlgMessageBox(): Button: SELECTED #3 (Cancel)" );				
				}				
				
				dialog.cancel();
				return;
			}
		};
		
		winAlert = new AlertDialog.Builder( this )
			.setIcon( R.drawable.icon )
			.setOnKeyListener( keyListener )
			//.setTitle( getResources().getString(R.string.dlgFailTitle) )
			//.setMessage( ListenMyStory.this.m_strResMsg )
			.setTitle( strTitle )
			.setMessage( strMessage )
			.setPositiveButton( getResources().getString(R.string.dlgBtn_OK), okListener )
			.setNegativeButton( getResources().getString(R.string.dlgBtn_CANCEL), okListener )
			.setView( viewDlgMessageBox );
		winDialog = winAlert.create();
		winDialog.show();
    }

    public void DlgContentsList(String strTitle, String strMessage) {
   		final Builder winAlert;
   		final Dialog winDialog;
       	LayoutInflater li = LayoutInflater.from( this );
       	final View viewDlg = li.inflate( R.layout.dlg_contents_listview, null );
       	
       	__DEBUG__( "DlgContentsList()" );
       	
     // Contents List Message
       	{
       		TextView tv = (TextView)viewDlg.findViewById( R.id.TextView_Message );
       		if( tv != null ) {
       			if( strMessage.equals("") )
       				tv.setText( "List of Contents" );
       			else
       				tv.setText( strMessage );
       		}
      	}

       	// Back Key
       	DialogInterface.OnKeyListener keyListener = new DialogInterface.OnKeyListener() {
   			@Override
   			public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
   				// TODO Auto-generated method stub
   				
   				if( keyCode == KeyEvent.KEYCODE_BACK )
   					return true;

   				return false;
   			}
   		};
       	
       	DialogInterface.OnClickListener okListener = new DialogInterface.OnClickListener() {
   			public void onClick(DialogInterface dialog, int which) {
   				// TODO Auto-generated method stub
   				
   				// OK
   				if( which == -1 ) {
   					__DEBUG__( "DlgContentsList(): Button: SELECTED #1 OK" );
   					//Toast.makeText( ListenMyStory.this, "...", Toast.LENGTH_SHORT ).show();
   				}
   				// Cancel #1
   				else if( which == -3 ) {
   					__DEBUG__( "DlgContentsList(): Button: SELECTED #2 Cancel" );
   				}
   				// Cancel #2
   				else if( which == -2 ) {
   					__DEBUG__( "DlgContentsList(): Button: SELECTED #3 (Cancel)" );				
   				}				
   				
   				dialog.cancel();
   				return;
   			}
   		};
   		
   		winAlert = new AlertDialog.Builder( this )
   		.setIcon( R.drawable.icon )
   		.setOnKeyListener( keyListener )
   		//.setTitle( getResources().getString(R.string.dlgFailTitle) )
   		//.setMessage( ListenMyStory.this.m_strResMsg )
   		.setTitle( strTitle )
   		//.setMessage( strMessage )
   		.setPositiveButton( getResources().getString(R.string.dlgBtn_OK), okListener )
   		.setNegativeButton( getResources().getString(R.string.dlgBtn_CANCEL), okListener )
   		.setView( viewDlg );
		winDialog = winAlert.create();
		winDialog.show();

   	    {
   	    	__DEBUG__( "DlgContentsList(): Init Resource List of Contents" );
   	    	
   	    	/*
   	    		// Layout for List of Contents
	   	    	+R.layout.dlg_contents_listview
	   	    	 - R.id.ListView_ContentsList
	   	    	+R.layout.dlg_contents_listview_item
	   	    	 - R.id.TextView_Contents_Item
   	    	*/
   	    	
   	    	m_ListViewResContents = (ListView)viewDlg.findViewById( R.id.ListView_ContentsList );

   	    	ArrayList<HashMap<String, String>> itemList = new ArrayList<HashMap<String, String>>();
   	    	
   	    	/*
   	    	// Row 1
   	    	HashMap<String, String> map = new HashMap<String, String>();
   	    	map.put( "menu", "item 1" );
   	    	itemList.add( map );

   	    	// Row 2
   	    	map = new HashMap<String, String>();
   	    	map.put( "menu", "item 2" );
   	    	itemList.add( map );

   	    	// Row 3
   	    	map = new HashMap<String, String>();
   	    	map.put( "menu", "item 3" );
   	    	itemList.add( map );

   	    	// Row 4
   	    	map = new HashMap<String, String>();
   	    	map.put( "menu", "item 4" );
   	    	itemList.add( map );

   	    	// Row 5
   	    	map = new HashMap<String, String>();
   	    	map.put( "menu", "item 5" );
   	    	itemList.add( map );
			*/

   	    	if( m_MainApp == null ) {
   	    		__DEBUG_ERROR__( "DlgContentsList(): m_MainApp == NULL" );
   	    		return;
   	    	}

   	    	for( int i = 0; i < m_MainApp.GetXmlResManage().size(); i++ ) {
   	    		__DEBUG__( "DlgContentsList(): " + m_MainApp.GetXmlResManage().get(i).GetNum() + " " + m_MainApp.GetXmlResManage().get(i).GetTitle() );
   	    		
   	   	    	HashMap<String, String> map = new HashMap<String, String>();
   	   	    	map.put( "num", m_MainApp.GetXmlResManage().get(i).GetNum() );
   	   	    	map.put( "item", m_MainApp.GetXmlResManage().get(i).GetTitle() );
   	   	    	itemList.add( map );
   	    	}

   	    	m_ListViewResContentsAdapter = new SimpleAdapter( this, itemList, R.layout.dlg_contents_listview_item,
   	    			new String[] {"num", "item"},
   	    			new int[] {R.id.TextView_Contents_Num, R.id.TextView_Contents_Item});
   	    	m_ListViewResContents.setAdapter( m_ListViewResContentsAdapter );
   	    	m_ListViewResContents.setTextFilterEnabled( true );
   	   		
   	   		/*
   	   		m_ListViewResContents.setOnScrollListener( new OnScrollListener() {
   				@Override
   				public void onScrollStateChanged(AbsListView view, int scrollState) {
   					// TODO Auto-generated method stub
   					switch( scrollState ) {
   						case SCROLL_STATE_FLING:
   						case SCROLL_STATE_TOUCH_SCROLL:
   						case SCROLL_STATE_IDLE:
   							break;
   					}
   				}
   				
   				@Override
   				public void onScroll(AbsListView view, int firstVisibleItem,
   						int visibleItemCount, int totalItemCount) {
   					// TODO Auto-generated method stub
   					
   					if( (firstVisibleItem+visibleItemCount) == (totalItemCount - 1) ) {
   						// ...
   					}
   					
   					if( m_ListViewResContents.getLastVisiblePosition() == (m_ListViewResContents.getCount() - 1) ) {
   						// ...
   					}
   				}
   			});
   			*/

   	    	m_ListViewResContents.setOnItemClickListener( new OnItemClickListener() {
   				@Override
   				public void onItemClick(AdapterView<?> a, View arg1, int position, long id) {
   					// TODO Auto-generated method stub
   					
   					__DEBUG__( "DlgContentsList(): onItemClick(): Selected Item Position = " + position + ", data = " + m_ListViewResContents.getItemAtPosition(position) );
   					m_Vibrator.vibrate( 20 );
   					
   					// position start at '0'
   					m_currentImagePosition = position - 1;
   					GetContentMoveTo( m_currentImagePosition );
   					winDialog.dismiss();
   				}
   			});
   	    }
/*   		
   		winAlert = new AlertDialog.Builder( this )
	   		.setIcon( R.drawable.icon )
	   		.setOnKeyListener( keyListener )
	   		//.setTitle( getResources().getString(R.string.dlgFailTitle) )
	   		//.setMessage( ListenMyStory.this.m_strResMsg )
	   		.setTitle( strTitle )
	   		//.setMessage( strMessage )
	   		.setPositiveButton( getResources().getString(R.string.dlgBtn_OK), okListener )
	   		.setNegativeButton( getResources().getString(R.string.dlgBtn_CANCEL), okListener )
	   		.setView( viewDlg );
   		winDialog = winAlert.create();
   		winDialog.show();
*/
	}

    // Load a resource from External Storage (SD card)
    public void DlgSDcardResourceList(String strTitle, String strMessage) {
   		final Builder winAlert;
   		final Dialog winDialog;
       	LayoutInflater li = LayoutInflater.from( this );
       	final View viewDlg = li.inflate( R.layout.dlg_contents_listview, null );
       	
       	__DEBUG__( "DlgSDcardResourceList()" );
       	
      	{
      		TextView tv = (TextView)viewDlg.findViewById( R.id.TextView_Message );
      		if( tv != null ) {
      			String strPath = Environment.getExternalStorageDirectory().getPath();
      			strPath = strPath + "/" + m_MainApp.GetConfManager().GetResPath() + "/";

      			if( strMessage.equals("") )
      				tv.setText( "Resource path: " + "\n   " + strPath );
      			else
      				tv.setText( strMessage );
      		}
      	}

       	// Back Key
       	DialogInterface.OnKeyListener keyListener = new DialogInterface.OnKeyListener() {
   			@Override
   			public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
   				// TODO Auto-generated method stub
   				
   				if( keyCode == KeyEvent.KEYCODE_BACK )
   					return true;

   				return false;
   			}
   		};
       	
       	DialogInterface.OnClickListener okListener = new DialogInterface.OnClickListener() {
   			public void onClick(DialogInterface dialog, int which) {
   				// TODO Auto-generated method stub
   				
   				// OK
   				if( which == -1 ) {
   					__DEBUG__( "DlgSDcardResourceList(): Button: SELECTED #1 OK" );
   					//Toast.makeText( ListenMyStory.this, "...", Toast.LENGTH_SHORT ).show();
   				}
   				// Cancel #1
   				else if( which == -3 ) {
   					__DEBUG__( "DlgSDcardResourceList(): Button: SELECTED #2 Cancel" );
   				}
   				// Cancel #2
   				else if( which == -2 ) {
   					__DEBUG__( "DlgSDcardResourceList(): Button: SELECTED #3 (Cancel)" );				
   				}				
   				
   				dialog.cancel();
   				return;
   			}
   		};
   		
   		winAlert = new AlertDialog.Builder( this )
   		.setIcon( R.drawable.icon )
   		.setOnKeyListener( keyListener )
   		//.setTitle( getResources().getString(R.string.dlgFailTitle) )
   		//.setMessage( ListenMyStory.this.m_strResMsg )
   		.setTitle( strTitle )
   		//.setMessage( strMessage )
   		.setPositiveButton( getResources().getString(R.string.dlgBtn_OK), okListener )
   		.setNegativeButton( getResources().getString(R.string.dlgBtn_CANCEL), okListener )
   		.setView( viewDlg );
		winDialog = winAlert.create();
		winDialog.show();

   	    {
   	    	__DEBUG__( "DlgSDcardResourceList(): Init Resource List of Contents" );
   	    	
   	    	/*
   	    		// Layout for List of Contents
	   	    	+R.layout.dlg_contents_listview
	   	    	 - R.id.ListView_ContentsList
	   	    	+R.layout.dlg_contents_listview_item
	   	    	 - R.id.TextView_Contents_Item
   	    	*/
   	    	
   	    	m_ListViewResContents = (ListView)viewDlg.findViewById( R.id.ListView_ContentsList );

   	    	ArrayList<HashMap<String, String>> itemList = new ArrayList<HashMap<String, String>>();
   	    	
   	    	/*
   	    	// Row 1
   	    	HashMap<String, String> map = new HashMap<String, String>();
   	    	map.put( "menu", "item 1" );
   	    	itemList.add( map );

   	    	// Row 2
   	    	map = new HashMap<String, String>();
   	    	map.put( "menu", "item 2" );
   	    	itemList.add( map );

   	    	// Row 3
   	    	map = new HashMap<String, String>();
   	    	map.put( "menu", "item 3" );
   	    	itemList.add( map );

   	    	// Row 4
   	    	map = new HashMap<String, String>();
   	    	map.put( "menu", "item 4" );
   	    	itemList.add( map );

   	    	// Row 5
   	    	map = new HashMap<String, String>();
   	    	map.put( "menu", "item 5" );
   	    	itemList.add( map );
			*/

   	    	if( m_MainApp == null ) {
   	    		__DEBUG_ERROR__( "DlgSDcardResourceList(): m_MainApp == NULL" );
   	    		return;
   	    	}

   	    	// Get File list from SD card
   	    	final String[] strFilelist = GetResourceFilesFromSDcard();
   	    	if( strFilelist == null ) {
   	    		__DEBUG_ERROR__( "DlgSDcardResourceList(): File List == NULL " );
   	    		return;
   	    	}

   	    	for( int i = 0; i < strFilelist.length; i++ ) {
   	    		__DEBUG__( "DlgSDcardResourceList(): index = " + i + ", Filename = " + strFilelist[i] );

   	   	    	HashMap<String, String> map = new HashMap<String, String>();
   	   	    	map.put( "num", Integer.toString(i) );
   	   	    	map.put( "item", strFilelist[i] );
   	   	    	itemList.add( map );
   	    	}

   	    	m_ListViewResContentsAdapter = new SimpleAdapter( this, itemList, R.layout.dlg_contents_listview_item,
   	    			new String[] {"num", "item"},
   	    			new int[] {R.id.TextView_Contents_Num, R.id.TextView_Contents_Item});
   	    	m_ListViewResContents.setAdapter( m_ListViewResContentsAdapter );
   	    	m_ListViewResContents.setTextFilterEnabled( true );
   	   		
   	   		/*
   	   		m_ListViewResContents.setOnScrollListener( new OnScrollListener() {
   				@Override
   				public void onScrollStateChanged(AbsListView view, int scrollState) {
   					// TODO Auto-generated method stub
   					switch( scrollState ) {
   						case SCROLL_STATE_FLING:
   						case SCROLL_STATE_TOUCH_SCROLL:
   						case SCROLL_STATE_IDLE:
   							break;
   					}
   				}
   				
   				@Override
   				public void onScroll(AbsListView view, int firstVisibleItem,
   						int visibleItemCount, int totalItemCount) {
   					// TODO Auto-generated method stub
   					
   					if( (firstVisibleItem+visibleItemCount) == (totalItemCount - 1) ) {
   						// ...
   					}
   					
   					if( m_ListViewResContents.getLastVisiblePosition() == (m_ListViewResContents.getCount() - 1) ) {
   						// ...
   					}
   				}
   			});
   			*/

   	    	m_ListViewResContents.setOnItemClickListener( new OnItemClickListener() {
   				@Override
   				public void onItemClick(AdapterView<?> a, View arg1, int position, long id) {
   					// TODO Auto-generated method stub
   					
   					__DEBUG__( "DlgSDcardResourceList(): onItemClick(): Selected Item Position = " + position + ", data = " + m_ListViewResContents.getItemAtPosition(position) );
   					m_Vibrator.vibrate( 20 );
   					
   					// position start at '0'
   					//m_currentImagePosition = position - 1;
   					//GetContentMoveTo( m_currentImagePosition );
   					
   					String strFilename = null;
   					strFilename = strFilelist[position];
   					LoadContentsFromSDcard( strFilename );
   					
					if( m_MainApp != null ) {
						m_MainApp.GetConfManager().SetLastFile( strFilename );
						m_MainApp.SetSaveConf();
					}
					else {
						__DEBUG_ERROR__( "DlgSDcardResourceList(): m_MainApp == NULL" );
						return;
					}

   					winDialog.dismiss();
   				}
   			});
   	    }
	}

// ---------------------------------------------
// Export
// ---------------------------------------------
	public void ExportResource(int resRawMediaFd, String strFilename) {
		__DEBUG__( "ExportResource()" );

		try {
			// TODO: Internal/External Storage
			String strFilePath = "./";
			String strFilePathInt = "";
			//String strFilePathExt = "/sdcard/";
			String strFilePathExt = Environment.getExternalStorageDirectory().getPath();
			strFilePathExt = strFilePathExt + "/";

			byte[] buf_readBytes = new byte[1024];
			int readBytes = 0;
			int offset = 0;
			int count = 1024;
			
			int duration = 0;

			// for External
			if( m_isSelectExternalStorage ){
				__DEBUG__( "ExportResource(): EXPORT: to External Storage" );
				__DEBUG__( "ExportResource(): EXPORT: Ext Storage = " + Environment.getExternalStorageState() );
				
				// Checks Mount
				if( android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED) ) {
					File path = Environment.getExternalStorageDirectory();
					StatFs stat = new StatFs( path.getPath() );
					long blockSize = stat.getBlockSize();
					long availableBlocks = stat.getAvailableBlocks();
					{
						AssetFileDescriptor afd = getResources().openRawResourceFd( resRawMediaFd );
						if( (availableBlocks * blockSize) < afd.getLength() ) {
							m_isAnErrorToExport = true;
							//Toast.makeText( this, "Out of External Storage Space", Toast.LENGTH_SHORT ).show();
							Toast.makeText( this, getResources().getString(R.string.Export_ExternalStorageFull), Toast.LENGTH_SHORT ).show();
							afd.close();
							return;
						}

						afd.close();
					}
				}
				else {
					m_isAnErrorToExport = true;
					//Toast.makeText( this, "External Storage Has Not Been Mounted, Mount First", Toast.LENGTH_SHORT ).show();
					Toast.makeText( this, getResources().getString(R.string.Export_ExternalStorageHasNotBeenMounted), Toast.LENGTH_SHORT ).show();
					return;  
				}

				// Export to Internal Storage
				strFilePath = strFilePathInt;
				if( m_isSelectExternalStorage ) {
					//strFilePathExt = Environment.getExternalStorageDirectory().getPath();
					//strFilePathExt = strFilePathExt + "/";
					strFilePath = strFilePathExt;
					__DEBUG__( "ExportResource(): EXPORT: External Storage Directory = " + strFilePath );
					//Toast.makeText( this, strFilePath, Toast.LENGTH_SHORT ).show();
				}
			}
			// for Internal
			else {
				__DEBUG__( "ExportResource(): EXPORT: Internal Only; SKIP" );

				m_isAnErrorToExport = true;
				//Toast.makeText( this, "Fail to Export: External Storage Only", Toast.LENGTH_SHORT ).show();
				Toast.makeText( this, getResources().getString(R.string.Export_Error_ExternalOnly), Toast.LENGTH_SHORT ).show();
				return;
			}

			if( m_isSelectExternalStorage ){
				// Resource
		    	AssetFileDescriptor afd = this.getResources().openRawResourceFd( resRawMediaFd );
		    	
				if( (new File(strFilePath + strFilename).exists()) == true ) {
					__DEBUG__( "ExportResource(): EXPORT: Exist = " + strFilePath + strFilename );
					__DEBUG__( "ExportResource(): EXPORT: Exist = " + "Internal Res Size = " + afd.getLength() + ", External Res Size = " + (new File(strFilePath + strFilename).length()) );
					if( (new File(strFilePath + strFilename).length()) == afd.getLength()) {
						m_isAnErrorToExport = true;
						//Toast.makeText( this, "External File Exist"), Toast.LENGTH_SHORT ).show();
						Toast.makeText( this, getResources().getString(R.string.Export_ExternalFileExist), Toast.LENGTH_SHORT ).show();
						afd.close();
						return;
					}
				}
	
				OutputStream osOUT = new FileOutputStream( strFilePath + strFilename );
				
				FileInputStream fis = afd.createInputStream();
				while( true ) {
					int bytes = fis.read( buf_readBytes );
					if( bytes <= 0 ) break;
					osOUT.write( buf_readBytes, 0, bytes );
				}
				
				osOUT.flush();
				osOUT.close();
				fis.close();
				afd.close();
			}
			else {
				// Checks Size of the Internal Storage
				File path = Environment.getDataDirectory();
				StatFs stat = new StatFs( path.getPath() );
				long blockSize = stat.getBlockSize();
				long availableBlocks = stat.getAvailableBlocks();
				{
					AssetFileDescriptor afd = getResources().openRawResourceFd( resRawMediaFd );
					if( (availableBlocks * blockSize) < afd.getLength() ) {
						m_isAnErrorToExport = true;
						//Toast.makeText( this, "Out of Internal Storage Space", Toast.LENGTH_SHORT ).show();
						Toast.makeText( this, getResources().getString(R.string.Export_InternalStorageFull), Toast.LENGTH_SHORT ).show();
						afd.close();
						return;
					}
					afd.close();
				}
			}
		}
		catch( IOException e ) {
			m_isAnErrorToExport = true;
			//Toast.makeText( this, "Fail to Export", Toast.LENGTH_SHORT ).show();
			//Toast.makeText( this, getResources().getString(R.string.Export_Error), Toast.LENGTH_SHORT ).show();

			//
			// TODO: Show Export Dialog
		}
		
		__DEBUG__( "ExportResource(): EXPORT: Exported..." );

		// Media Scan
		sendBroadcast( new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())) );

		// Exported
		//Toast.makeText( this, "Export Done"), Toast.LENGTH_SHORT ).show();
		Toast.makeText( this, getResources().getString(R.string.Export_Done), Toast.LENGTH_SHORT ).show();
		m_isAnErrorToExport = false;
	}



// ---------------------IMPLEMENTATION----------------------



//-------------------------------------------
// Load Resource of This APK
//-------------------------------------------
    public void ReleaseLoadInternalResource(boolean isAll) {
 		__DEBUG__( "ReleaseLoadInternalResource()" );
 		
 		try {
			if( m_LIR_baOS != null ) m_LIR_baOS.close();
			if( m_LIR_zIS != null ) m_LIR_zIS.close();
			if( m_LIR_afd != null ) m_LIR_afd.close();
			if( m_LIR_is != null ) m_LIR_is.close();
			if( isAll ) {
				if( m_TmpFile != null )
					m_TmpFile.delete();
				
				File fpCacheDir = null;
				fpCacheDir = getCacheDir();
				if( fpCacheDir != null ) {
					String[] str = fpCacheDir.list( null );
					boolean isAllDeleted = true;
					for( int i = 0; i < str.length; i++ ) {
						// NOTE: "deleteFile" doesn't support a path separator
						//deleteFile( fpCacheDir.getPath() + "/" + str[i] );
						if( new File(fpCacheDir, str[i]).delete() )
							__DEBUG__( "ReleaseLoadInternalResource(): DELETED: " + fpCacheDir.getAbsolutePath() + "/" + str[i] );
						else {
							isAllDeleted = false;
							__DEBUG_ERROR__( "ReleaseLoadInternalResource(): FAIL TO DELETED: " + fpCacheDir.getAbsolutePath() + "/" + str[i] );
						}
					}
					
					if( isAllDeleted )
						__DEBUG__( "ReleaseLoadInternalResource(): Deleted All Cached files" );
					else
						__DEBUG_ERROR__( "ReleaseLoadInternalResource(): Fail to Deleted All Cached files" );
				}
				fpCacheDir = null;
			}

			m_LIR_baOS = null;
			m_LIR_zIS = null;
			m_LIR_afd = null;
			m_LIR_is = null;
			if( isAll )
				m_TmpFile = null;
		}
 		catch( IOException e ) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
 			__DEBUG_ERROR__( "ReleaseLoadInternalResource(): IOException: " + e.getMessage() );
		}
 		catch( Exception e ) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
 			__DEBUG_ERROR__( "ReleaseLoadInternalResource(): Exception: " + e.getMessage() );
		}
    }

 	public void LoadFromResourceOfThisAPK(boolean isAll, boolean isSDcard) {
 		__DEBUG__( "LoadFromResourceOfThisAPK()" );

		// SD card
 		if( isSDcard ) {
 			if( m_MainApp != null ) {
 				String strLastFile = "";
 				strLastFile = m_MainApp.GetConfManager().GetLastFile();
 				if( !strLastFile.equals("") ) {
 					//LoadContentsFromSDcard( strLastFile );
 					//GetContentInit();
 					
 					LoadFromResourceOfSDcard( false, strLastFile );
 				}
 				else {
 					Log.d( TAG, "LoadFromResourceOfThisAPK(): Last Opened File == NULL" );
 					return;
 				}
 			}
 			else {
 				Log.d( TAG, "LoadFromResourceOfThisAPK(): m_MainApp == NULL" );
 				return;
 			}
 			
 			return;
 		}
 
 		ReleaseLoadInternalResource( isAll );

 		//m_LIR_afd = getResources().openRawResourceFd( R.raw.a3 );
 		m_LIR_afd = getResources().openRawResourceFd( /*R.raw.respkg*/m_ResPackage );
		try {
			m_LIR_is = m_LIR_afd.createInputStream();
			m_LIR_zIS = new ZipInputStream( m_LIR_is );
			m_LIR_zOS = null;
		}
		catch( IOException e ) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
			__DEBUG_ERROR__( "LoadFromResourceOfThisAPK(): Exception: " + e.getMessage() );
		}
 	}

 	public void LoadFromResourceOfSDcard(boolean isAll, String strFilename) {
 		__DEBUG__( "LoadFromResourceOfSDcard()" );
 		
		if( strFilename == null || strFilename.equals("") ) {
			__DEBUG__( "LoadFromResourceOfSDcard(): Cannot load a resource file" + "\"" + strFilename + "\"" );
        	Toast.makeText( ListenMyStory.this, "Cannot load a resource file" + "\"" + strFilename + "\"", Toast.LENGTH_SHORT ).show();
			return;
		}
 		
 		ReleaseLoadInternalResource( isAll );

 		try {
			String strFilePath = "./";
			String strFilePathInt = "";
			//String strFilePathExt = "/sdcard/";
			String strFilePathExt = Environment.getExternalStorageDirectory().getPath();
			String strResFilename = strFilename;
			strFilePathExt = strFilePathExt + "/";

			__DEBUG__( "LoadFromResourceOfSDcard(): External Storage = " + Environment.getExternalStorageState() );

			if( m_MainApp == null ) {
				__DEBUG_ERROR__( "LoadFromResourceOfSDcard(): m_MainApp == NULL" );
				return;
			}

			// Get resource filename with absolute path
			// e.g., "/mnt/sdcard/" + "ListenMyStory" + "/" + "test.zip"
			// so, "/mnt/sdcard/ListenMyStory/test.zip"
			strFilePath = strFilePathExt;
			strResFilename = strFilePathExt + m_MainApp.GetConfManager().GetResPath() + "/" + strResFilename;

			if( android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED) ) {
				if( (new File(strResFilename).exists()) ) {
					__DEBUG__( "LoadFromResourceOfSDcard(): Found: \"" + strResFilename + "\"" );
					//Toast.makeText( this, "\"" + strResFilename + "\" " + getResources().getString(R.string.Export_FoundSuchFileDirectory), Toast.LENGTH_SHORT ).show();

					try {
						m_LIR_is = new FileInputStream( strResFilename );
						m_LIR_zIS = new ZipInputStream( m_LIR_is );
						m_LIR_zOS = null;
					}
					catch( IOException e ) {
						// TODO Auto-generated catch block
						//e.printStackTrace();
						__DEBUG_ERROR__( "LoadFromResourceOfSDcard(): Exception: " + e.getMessage() );
						return;
					}
/*
					// Get resource test
					{
						int MAX_BUF_SIZE = 2048;
						int MAX_BUF_SIZE_XML = 1024;
						ImageView iv = (ImageView)findViewById( R.id.ImageView_Pics );

						try {
							m_LIR_is = new FileInputStream( strResFilename );
							m_LIR_zIS = new ZipInputStream( m_LIR_is );

							for( ZipEntry zEntry = m_LIR_zIS.getNextEntry(); zEntry != null; zEntry = m_LIR_zIS.getNextEntry() ) {
								//__DEBUG__( "LoadFromResourceOfSDcard(): filename = " + zEntry.getName() );

								if( zEntry.getName().equals("1.jpg") ) {
									byte data[] = new byte[MAX_BUF_SIZE];

									__DEBUG__( "LoadFromResourceOfSDcard(): found: " + zEntry.getName() );

									m_LIR_baOS = new ByteArrayOutputStream();
									while( true ) {
										int count = m_LIR_zIS.read( data, 0, MAX_BUF_SIZE );
										if( count <= 0 ) break;
										
										//m_LIR_bOS.write( data, 0, count );
										m_LIR_baOS.write( data, 0, count );
									}
									
									__DEBUG__( "LoadFromResourceOfSDcard(): Zip Entry length = " + m_LIR_baOS.toByteArray().length );
				
									Bitmap bmp = BitmapFactory.decodeByteArray( m_LIR_baOS.toByteArray(), 0, m_LIR_baOS.toByteArray().length );
									if( bmp != null ) {
										int w, h;
										android.view.ViewGroup.LayoutParams lp = iv.getLayoutParams();
				
										w = lp.width;
										h = lp.height;
				
										__DEBUG__( "LoadFromResourceOfSDcard(): Terminal width, height = " + w + ", " + h );
										if( w == -1 )
											w = getWindowManager().getDefaultDisplay().getWidth();
				
										iv.setImageBitmap( Bitmap.createScaledBitmap(bmp, w, h, true) );
										bmp.recycle();
									}

									break;
								}
							}
						}
						catch( IOException e ) {
							// TODO Auto-generated catch block
							//e.printStackTrace();
							__DEBUG_ERROR__( "LoadFromResourceOfSDcard(): IOException: " + e.getMessage() );
							return;
						}
						catch( Exception e ) {
							// TODO Auto-generated catch block
							//e.printStackTrace();
							__DEBUG_ERROR__( "LoadFromResourceOfSDcard(): Exception: " + e.getMessage() );
							return;
						}
					}
*/
				}
				else {
					__DEBUG__( "LoadFromResourceOfSDcard(): Not Found: \"" + strResFilename + "\"" );
					Toast.makeText( this, "\"" + strResFilename + "\" "  + getResources().getString(R.string.Export_Error_NoFoundSuchFileDirectory), Toast.LENGTH_SHORT ).show();
					return;
				}
			}
 		}
 		catch( Exception e ) {
 			__DEBUG_ERROR__( "LoadFromResourceOfSDcard(): Exception: " + e.getMessage() );
 		}
 	}

 	public String GetSDcardPath() {
 		__DEBUG__( "GetSDcardPath()" );
 		
 		try {
			String strFilePath = "./";
			String strFilePathInt = "";
			//String strFilePathExt = "/sdcard/";
			String strFilePathExt = Environment.getExternalStorageDirectory().getPath();

			__DEBUG__( "GetSDcardPath(): External Storage = " + Environment.getExternalStorageState() );

			if( m_MainApp == null ) {
				__DEBUG_ERROR__( "GetSDcardPath(): m_MainApp == NULL" );
				return null;
			}

			// Get absolute path of the SD card
			// e.g., "/mnt/sdcard/"
			strFilePath = strFilePathExt + "/";
			
			return strFilePath;
 		}
 		catch( Exception e ) {
 			__DEBUG_ERROR__( "GetSDcardPath(): Exception: " + e.getMessage() );
 			return null;
 		}
 	}

 	public String[] GetResourceFilesFromSDcard() {
 		__DEBUG__( "GetResourceFilesFromSDcard()" );

 		try {
			String strFilePath = "./";
			String strFilePathInt = "";
			//String strFilePathExt = "/sdcard/";
			String strFilePathExt = Environment.getExternalStorageDirectory().getPath();
			//String strResFilename = "";
			strFilePathExt = strFilePathExt + "/";

			__DEBUG__( "GetResourceFilesFromSDcard(): External Storage = " + Environment.getExternalStorageState() );

			if( m_MainApp == null ) {
				__DEBUG_ERROR__( "GetResourceFilesFromSDcard(): m_MainApp == NULL" );
				return null;
			}

			// Get resource filename with absolute path
			// e.g., "/mnt/sdcard/" + "ListenMyStory" + "/"
			//strFilePath = strFilePathExt;
			strFilePath = strFilePathExt + m_MainApp.GetConfManager().GetResPath() + "/";

			if( android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED) ) {
				File fp = new File( strFilePath );

				if( fp.exists() && fp.isDirectory() ) {
					__DEBUG__( "GetResourceFilesFromSDcard(): Found: \"" + strFilePath + "\"" );
					//Toast.makeText( this, "\"" + strFilePath + "\" " + getResources().getString(R.string.Export_FoundSuchFileDirectory), Toast.LENGTH_SHORT ).show();

					try {
						String[] strFilelist = new String[fp.list().length];
						for( int i = 0; i < fp.list().length; i++ ) {
							__DEBUG__( "GetResourceFilesFromSDcard(): Index = " + i + ", Filename = " + fp.list()[i] );
							//strFilelist[i] = strFilePath + fp.list()[i];
							strFilelist[i] = fp.list()[i];
						}
						
						fp = null;
						return strFilelist;
					}
					catch( Exception e ) {
						// TODO Auto-generated catch block
						//e.printStackTrace();
						__DEBUG_ERROR__( "GetResourceFilesFromSDcard(): Exception: " + e.getMessage() );
						return null;
					}
				}
				else {
					__DEBUG__( "GetResourceFilesFromSDcard(): Not Found: \"" + strFilePath + "\"" );
					Toast.makeText( this, "\"" + strFilePath + "\" "  + getResources().getString(R.string.Export_Error_NoFoundSuchFileDirectory), Toast.LENGTH_SHORT ).show();
					fp = null;
					return null;
				}
			}
 		}
 		catch( Exception e ) {
 			__DEBUG_ERROR__( "GetResourceFilesFromSDcard(): Exception: " + e.getMessage() );
 			return null;
 		}
 		
 		return null;
 	}

//-------------------------------------------
// Get content
//-------------------------------------------
 	public void SetCurrentPosition(int pos) {
 		__DEBUG__( "SetCurrentPosition()" );

 		m_currentImagePosition = pos;
 	}

 	public int GetCurrentPosition() {
 		__DEBUG__( "GetCurrentPosition()" );

 		return m_currentImagePosition;
 	}

 	// Get an Xml and first Image 
	public boolean GetContentInit() {
		__DEBUG__( "GetContentInit()" );
		
		int MAX_BUF_SIZE = 2048;
		int MAX_BUF_SIZE_XML = 1024;
		TextView tv = (TextView)findViewById( R.id.TextView_Text );
		ImageView iv = (ImageView)findViewById( R.id.ImageView_Pics );
		String strA = "";
		boolean foundXml = false;
		boolean foundPic = false;
		boolean foundText = false;

		m_currentImagePosition = 0;

		try {
			for( ZipEntry zEntry = m_LIR_zIS.getNextEntry(); zEntry != null; zEntry = m_LIR_zIS.getNextEntry() ) {
				//__DEBUG__( "GetContentInit(): entry name = " + zEntry.getName() );
				//strA = zEntry.getName() + ", ";
				
				//if( zEntry.getName().equals( "gallery_photo_1.jpg") ) {
				if( (foundXml == false) && (zEntry.getName().contains(m_ResPackageXml)) ) {
					foundXml = true;

					//__DEBUG__( "GetContentInit(): found: " + m_ResPackageXml + ".xml" );
					__DEBUG__( "GetContentInit(): found: " + zEntry.getName() );

					// Copy text.xml to temporary(cache) directory of the Activity
					{
						// Checks Size of the Internal Storage
						File path = Environment.getDataDirectory();
						StatFs stat = new StatFs( path.getPath() );
						long blockSize = stat.getBlockSize();
						long availableBlocks = stat.getAvailableBlocks();
						{
							//AssetFileDescriptor afd = getResources().openRawResourceFd( m_ResRawMediaFd );
							//if( (availableBlocks * blockSize) < afd.getLength() ) {
							if( (availableBlocks * blockSize) < zEntry.getSize() ) {
								__DEBUG_ERROR__( "GetContentInit(): Out of Internal Storage" );
								//Toast.makeText( this, "Out of Internal Storage", Toast.LENGTH_LONG ).show();
								//Toast.makeText( this, getResources().getString(R.string.ExportInternalStorageFull), Toast.LENGTH_LONG ).show();

								//afd.close();
								return false;
							}

							//afd.close();
						}

						try {
							//AssetFileDescriptor afd = getResources().openRawResourceFd( m_ResRawMediaFd );
							//FileInputStream fis = afd.createInputStream();
							String strTmpFilename = "";
							
							if( m_TmpFile != null )
								m_TmpFile.delete();
					
							//__DEBUG__( "GetContentInit(): App Full Size = ", Long.toString(fis.getChannel().size()) );
							//__DEBUG__( "GetContentInit(): Res Position = ", Long.toString(fis.getChannel().position()) );
							//__DEBUG__( "GetContentInit(): Res Size = ", Long.toString(afd.getLength()) );
					
							{
								byte[] bufReadBytesFile = new byte[MAX_BUF_SIZE_XML];
								File cacheDir = getCacheDir();
								String strFilename = "text";
								m_TmpFile = File.createTempFile( strFilename, ".xml", cacheDir );
								OutputStream osOUT = new FileOutputStream( m_TmpFile );
								
								__DEBUG__( "GetContentInit(): Filename = " + m_TmpFile.getPath() );

								while( true ) {
									int count = m_LIR_zIS.read( bufReadBytesFile, 0, MAX_BUF_SIZE_XML );
									if( count <= 0 ) break;
									osOUT.write( bufReadBytesFile, 0, count );
								}

								osOUT.flush();
								strTmpFilename = m_TmpFile.getAbsolutePath();
								osOUT.close();
							}

							__DEBUG__( "GetContentInit(): File = " + strTmpFilename );

							//afd.close();
							//fis.close();
						}
						catch( Exception e ) {
							__DEBUG_ERROR__( "GetContentInit(): Exception: " + e.getMessage() );

							if( m_TmpFile != null ) {
								m_TmpFile.delete();
								m_TmpFile = null;
							}

							//Toast.makeText( this, "Error: Export", Toast.LENGTH_LONG ).show();
							//Toast.makeText( this, getResources().getString(R.string.ExportError), Toast.LENGTH_LONG ).show();
							//exportDlg();
							
							return false;
						}
										
						__DEBUG__( "GetContentInit(): Exported..." );
						//Toast.makeText( this, "Export: OK", Toast.LENGTH_LONG ).show();
						//Toast.makeText( this, getResources().getString(R.string.ExportDoneVideo), Toast.LENGTH_LONG ).show();
					}

					//

					if( m_currentImagePosition <= 0 )
						continue;
					else if( !foundText )
						continue;
					else
						break;
				}

				if( m_currentImagePosition == 0 ) {
					//if( zEntry.getName().contains(".jpg") ) {
					if( zEntry.getName().equals("cover.jpg") ) {
						byte data[] = new byte[MAX_BUF_SIZE];
	
						foundPic = true;
						__DEBUG__( "GetContentInit(): found: " + zEntry.getName() );

						m_LIR_baOS = new ByteArrayOutputStream();
						while( true ) {
							int count = m_LIR_zIS.read( data, 0, MAX_BUF_SIZE );
							if( count <= 0 ) break;
							
							//m_LIR_bOS.write( data, 0, count );
							m_LIR_baOS.write( data, 0, count );
						}
						
						__DEBUG__( "GetContentInit(): Zip Entry length = " + m_LIR_baOS.toByteArray().length );
	
						Bitmap bmp = BitmapFactory.decodeByteArray( m_LIR_baOS.toByteArray(), 0, m_LIR_baOS.toByteArray().length );
						if( bmp != null ) {
							int w, h;
							android.view.ViewGroup.LayoutParams lp = iv.getLayoutParams();
	
							w = lp.width;
							h = lp.height;
	
							__DEBUG__( "GetContentInit(): Terminal width, height = " + w + ", " + h );
							if( w == -1 )
								w = getWindowManager().getDefaultDisplay().getWidth();
	
							iv.setImageBitmap( Bitmap.createScaledBitmap(bmp, w, h, true) );
							bmp.recycle();
						}

						//m_currentImagePosition += 1;
						//tv.setText( strA );
						
						if( foundXml == true && foundText == true )
							break;
					}
				}

				if( !foundText ) {
					if( zEntry.getName().equals("cover.txt") ) {
						__DEBUG__( "GetContentInit(): found: " + zEntry.getName() );
						foundText = true;
						{
							byte[] bufReadBytesFile = new byte[MAX_BUF_SIZE_XML];
							File cacheDir = getCacheDir();
							String strFilename = "chapter_text";
							File tmpFile = File.createTempFile( strFilename, ".txt", cacheDir );
							OutputStream osOUT = new FileOutputStream( tmpFile );
							
							__DEBUG__( "GetContentInit(): Filename = " + tmpFile.getPath() );

							while( true ) {
								int count = m_LIR_zIS.read( bufReadBytesFile, 0, MAX_BUF_SIZE_XML );
								if( count <= 0 ) break;
								osOUT.write( bufReadBytesFile, 0, count );
							}

							osOUT.flush();
							osOUT.close();
					
							InputStreamReader isr = new InputStreamReader( GetInputStream(tmpFile) );
							BufferedReader br = new BufferedReader( isr );
							String strGetLine;
							StringBuilder sb = new StringBuilder();

							try {
								while( (strGetLine = br.readLine()) != null ){ 
									sb.append( strGetLine ); 
									sb.append( "\n" );
								}
								br.close();
								isr.close();
								
								TextView tv_text = (TextView)findViewById( R.id.TextView_Text );
								if( tv_text != null )
									tv_text.setText( sb );
							}
							catch (IOException e) {
								// TODO Auto-generated catch block
								//e.printStackTrace();
								__DEBUG_ERROR__( "GetContentInit(): IOException: " + e.getMessage() );
								
								if( tmpFile != null ) {
									tmpFile.delete();
									tmpFile = null;
								}
								
								return false;
							}
							
							if( tmpFile != null ) {
								tmpFile.delete();
								tmpFile = null;
							}
						}

						//if( foundXml == true && m_currentImagePosition > 0 )
						if( foundXml == true && foundPic == true )
							break;
					}
				}

				//if( m_currentImagePosition > 0 ) {
				if( foundPic ) {
					__DEBUG__( "GetContentInit(): Current Image Position = " + m_currentImagePosition );
					
					if( foundXml == true && foundText == true )
						break;
				}
			}

			// Show the Blank Image if Image isn't available
			if( m_currentImagePosition == 0 ) {
				TextView tv_textPosition = (TextView)findViewById( R.id.TextView_Position );
				if( tv_textPosition != null ) {
					String str = "(" + Integer.toString(GetCurrentPosition()) + "/" + Integer.toString(XML_GetEntryCount()) + ")";
					tv_textPosition.setText( str );
				}

				if( !foundPic ) {
					if( iv != null )
						iv.setImageResource( R.drawable.no_image_available );
				}
			}
			
			// Scroll To Top (0, 0)
			{
				android.widget.ScrollView sv = (android.widget.ScrollView)findViewById( R.id.ScrollView_TextBody );
				if( sv != null ) {
					sv.scrollTo( 0, 0 );
				}
			}
		}
		catch( IOException e ) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
			__DEBUG_ERROR__( "GetContentInit(): Exception: " + e.getMessage() );
			return false;
		}
		
		return true;
	}

	public boolean GetPrepare() {
		__DEBUG__( "GetPrepare()" );

		boolean ret = false;

		if( m_xmlResList == null )
			ret = false;
		else
			ret = true;
		
		if( m_MainApp != null ) {
			String strLastFile = "";
			strLastFile = m_MainApp.GetConfManager().GetLastFile();
			if( !strLastFile.equals("") ) {
				//LoadContentsFromSDcard( strLastFile );
				//GetContentInit();
				
				//LoadFromResourceOfSDcard( false, strLastFile );
				ret = true;
			}
			else {
				Log.d( TAG, "GetPrepare(): Last Opened File == NULL" );
				ret = false;
			}
		}
		else {
			Log.d( TAG, "GetPrepare(): m_MainApp == NULL" );
			ret = false;
		}

		return ret;
	}

	public InputStream GetInputStream(File file) {
		__DEBUG__( "GetInputStream()" );

		if( file != null ) {
			InputStream is = null;

			try {
				is = new FileInputStream( file );
			}
			catch( FileNotFoundException e ) {
				// TODO Auto-generated catch block
				//e.printStackTrace();
				__DEBUG_ERROR__( "GetXmlStream(): FileNotFoundException: XML FILE == NULL" );

				is = null;
				return null;
			}
			catch( Exception e ) {
				// TODO Auto-generated catch block
				//e.printStackTrace();
				__DEBUG_ERROR__( "GetXmlStream(): Exception: XML FILE == NULL" );

				is = null;
				return null;
			}

			return is;
		}

		__DEBUG__( "GetXmlStream(): XML FILE == NULL" );
		return null;
	}

	public InputStream GetXmlStream() {
		__DEBUG__( "GetXmlStream()" );

		if( m_TmpFile != null ) {
			InputStream is = null;

			try {
				is = new FileInputStream( m_TmpFile );
			}
			catch( FileNotFoundException e ) {
				// TODO Auto-generated catch block
				//e.printStackTrace();
				__DEBUG_ERROR__( "GetXmlStream(): FileNotFoundException: XML FILE == NULL" );

				is = null;
				return null;
			}
			catch( Exception e ) {
				// TODO Auto-generated catch block
				//e.printStackTrace();
				__DEBUG_ERROR__( "GetXmlStream(): Exception: XML FILE == NULL" );

				is = null;
				return null;
			}

			return is;
		}

		__DEBUG__( "GetXmlStream(): XML FILE == NULL" );
		return null;
	}

	public void GetContentCurrently() {
		__DEBUG__( "GetContentCurrently()" );
		
		int MAX_BUF_SIZE = 2048;
		//TextView tv_title = (TextView)findViewById( R.id.TextView_Title );
		//TextView tv_text = (TextView)findViewById( R.id.TextView_Text );
		ImageView iv = (ImageView)findViewById( R.id.ImageView_Pics );
		String strA = "";

		LoadFromResourceOfThisAPK( false, true );
		try {
			for( ZipEntry zEntry = m_LIR_zIS.getNextEntry(); zEntry != null; zEntry = m_LIR_zIS.getNextEntry() ) {
				//__DEBUG__( "GetContentNext(): entry name = " + zEntry.getName() );
				//strA = zEntry.getName();
				__DEBUG__( "GetContentCurrently(): EntryName = " + strA );

				//xmlResManage xmlEntry = XML_GetEntry( true );
				xmlResManage xmlEntry = m_xmlResList.get( m_currentImagePosition );
				if( xmlEntry == null ) {
					__DEBUG_ERROR__( "GetContentCurrently(): " + "xmlEntry == NULL" );
					return;
				}
				else
					__DEBUG__( "GetContentCurrently(): " + "xmlEntry = \"" + xmlEntry.GetPics() + "\"" );

				if( zEntry.getName().equals(xmlEntry.GetPics()) ) {
					byte data[] = new byte[MAX_BUF_SIZE];

					m_LIR_baOS = new ByteArrayOutputStream();
					while( true ) {
						int count = m_LIR_zIS.read( data, 0, MAX_BUF_SIZE );
						if( count <= 0 ) break;
						
						//m_LIR_bOS.write( data, 0, count );
						m_LIR_baOS.write( data, 0, count );
					}
					
					__DEBUG__( "GetContentCurrently(): Zip Entry length = " + m_LIR_baOS.toByteArray().length );

					Bitmap bmp = BitmapFactory.decodeByteArray( /*zEntry.getExtra()*/m_LIR_baOS.toByteArray(), 0, /*zEntry.getExtra().length*/m_LIR_baOS.toByteArray().length );
					if( bmp != null ) {
						int w, h;
						android.view.ViewGroup.LayoutParams lp = iv.getLayoutParams();

						w = lp.width;
						h = lp.height;

						__DEBUG__( "GetContentCurrently(): Terminal width, height = " + w + ", " + h );
						if( w == -1 )
							w = getWindowManager().getDefaultDisplay().getWidth();

						iv.setImageBitmap( Bitmap.createScaledBitmap(bmp, w, h, true) );
						bmp.recycle();
					}

					/*					
					m_currentImagePosition += 1;

					strA = xmlEntry.GetTitle();
					if( tv_title != null )
						tv_title.setText( strA );

					strA = "";
					strA = xmlEntry.GetText();
					if( tv_text != null )
						tv_text.setText( strA );
					*/

					break;
				}
			}
		}
		catch (IOException e) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
			__DEBUG_ERROR__( "GetContentCurrently(): Exception: " + e.getMessage() );
		}
	}

	public void GetContentPrevious() {
		__DEBUG__( "GetContentPrevious()" );

		int MAX_BUF_SIZE = 2048;
		int MAX_BUF_SIZE_TEXT = 1024;
		TextView tv_title = (TextView)findViewById( R.id.TextView_Title );
		TextView tv_text = (TextView)findViewById( R.id.TextView_Text );
		ImageView iv = (ImageView)findViewById( R.id.ImageView_Pics );
		String strA = "";
		long curImgPos = 0;
		boolean foundPic = false;
		boolean foundText = false;

		LoadFromResourceOfThisAPK( false, true );
		try {
			LoadFromResourceOfThisAPK( false, true );
			xmlResManage xmlEntry = null;
			
			for( ZipEntry zEntry = m_LIR_zIS.getNextEntry(); zEntry != null; zEntry = m_LIR_zIS.getNextEntry() ) {
				//__DEBUG__( "GetContentPrevious(): entry name = " + zEntry.getName() );
				//strA = zEntry.getName();
				__DEBUG__( "GetContentPrevious(): EntryName = " + strA );

				if( !foundPic && !foundText ) {
					xmlEntry = null;
					xmlEntry = XML_GetEntry( false );
				}

				//xmlResManage xmlEntry = XML_GetEntry( false );
				if( xmlEntry == null ) {
					__DEBUG_ERROR__( "GetContentPrevious(): " + "xmlEntry == NULL" );
					return;
				}
				else
					__DEBUG__( "GetContentPrevious():  " + "xmlEntry = \"" + xmlEntry.GetPics() + "\"" );

				if( foundPic == false && zEntry.getName().equals(xmlEntry.GetPics()) ) {
					byte data[] = new byte[MAX_BUF_SIZE];

					foundPic = true;
					m_LIR_baOS = new ByteArrayOutputStream();
					while( true ) {
						int count = m_LIR_zIS.read( data, 0, MAX_BUF_SIZE );
						if( count <= 0 ) break;
						
						//m_LIR_bOS.write( data, 0, count );
						m_LIR_baOS.write( data, 0, count );
					}
					
					if( m_LIR_baOS.toByteArray() == null ) {
						__DEBUG_ERROR__( "GetContentPrevious(): Zip Entry Image toByteArray() == NULL" );
						return;
					}

					__DEBUG__( "GetContentPrevious(): Zip Entry length = " + m_LIR_baOS.toByteArray().length );

					Bitmap bmp = BitmapFactory.decodeByteArray( /*zEntry.getExtra()*/m_LIR_baOS.toByteArray(), 0, /*zEntry.getExtra().length*/m_LIR_baOS.toByteArray().length );
					if( bmp != null ) {
						int w, h;
						android.view.ViewGroup.LayoutParams lp = iv.getLayoutParams();

						w = lp.width;
						h = lp.height;

						__DEBUG__( "GetContentPrevious(): Terminal width, height = " + w + ", " + h );
						if( w == -1 )
							w = getWindowManager().getDefaultDisplay().getWidth();

						iv.setImageBitmap( Bitmap.createScaledBitmap(bmp, w, h, true) );
						bmp.recycle();
					}

					m_currentImagePosition -= 1;

					strA = xmlEntry.GetTitle();
					if( tv_title != null )
						tv_title.setText( strA );

					/*
					strA = "";
					strA = xmlEntry.GetText();
					if( tv_text != null )
						tv_text.setText( strA );

					break;
					*/
					
					TextView tv_textPosition = (TextView)findViewById( R.id.TextView_Position );
					if( tv_textPosition != null ) {
						String str = "(" + Integer.toString(GetCurrentPosition()) + "/" + Integer.toString(XML_GetEntryCount()) + ")";
						tv_textPosition.setText( str );
					}

					if( !foundText )
						continue;
				}

				if( !foundText ) {
					if( zEntry.getName().equals(xmlEntry.GetText()) ) {
						__DEBUG__( "GetContentPrevious(): found: " + zEntry.getName() );

						foundText = true;
						{
							byte[] bufReadBytesFile = new byte[MAX_BUF_SIZE_TEXT];
							File cacheDir = getCacheDir();
							String strFilename = "chapter_text";
							File tmpFile = File.createTempFile( strFilename, ".txt", cacheDir );
							OutputStream osOUT = new FileOutputStream( tmpFile );
							
							__DEBUG__( "GetContentPrevious(): Filename = " + tmpFile.getPath() );

							while( true ) {
								int count = m_LIR_zIS.read( bufReadBytesFile, 0, MAX_BUF_SIZE_TEXT );
								if( count <= 0 ) break;
								osOUT.write( bufReadBytesFile, 0, count );
							}

							osOUT.flush();
							osOUT.close();
					
							InputStreamReader isr = new InputStreamReader( GetInputStream(tmpFile) );
							BufferedReader br = new BufferedReader( isr );
							String strGetLine;
							StringBuilder sb = new StringBuilder();

							try {
								while( (strGetLine = br.readLine()) != null ){ 
									sb.append( strGetLine ); 
									sb.append( "\n" );
								}
								br.close();
								isr.close();
								
								if( tv_text != null )
									tv_text.setText( sb );
							}
							catch (IOException e) {
								// TODO Auto-generated catch block
								//e.printStackTrace();
								__DEBUG_ERROR__( "GetContentPrevious(): IOException: " + e.getMessage() );
								
								if( tmpFile != null ) {
									tmpFile.delete();
									tmpFile = null;
								}
								
								return;
							}
							
							if( tmpFile != null ) {
								tmpFile.delete();
								tmpFile = null;
							}
						}

						if( foundPic == true )
							break;
					}
				}
			}
			
			// Show the Blank Image if Image isn't available
			if( foundPic == false ) {
				foundPic = true;
				m_currentImagePosition -= 1;

				strA = xmlEntry.GetTitle();
				if( tv_title != null )
					tv_title.setText( strA );

				TextView tv_textPosition = (TextView)findViewById( R.id.TextView_Position );
				if( tv_textPosition != null ) {
					String str = "(" + Integer.toString(GetCurrentPosition()) + "/" + Integer.toString(XML_GetEntryCount()) + ")";
					tv_textPosition.setText( str );
				}
				
				if( iv != null ) {
					iv.setImageResource( R.drawable.no_image_available );
				}
			}
			
			// Scroll To Top (0, 0)
			{
				android.widget.ScrollView sv = (android.widget.ScrollView)findViewById( R.id.ScrollView_TextBody );
				if( sv != null ) {
					sv.scrollTo( 0, 0 );
				}
			}
		}
		catch (IOException e) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
			__DEBUG_ERROR__( "GetContentPrevious(): Exception: " + e.getMessage() );
		}
	}

	public void GetContentNext() {
		__DEBUG__( "GetContentNext()" );
		
		int MAX_BUF_SIZE = 2048;
		int MAX_BUF_SIZE_TEXT = 1024;
		TextView tv_title = (TextView)findViewById( R.id.TextView_Title );
		TextView tv_text = (TextView)findViewById( R.id.TextView_Text );
		ImageView iv = (ImageView)findViewById( R.id.ImageView_Pics );
		String strA = "";
		boolean foundPic = false;
		boolean foundText = false;

		LoadFromResourceOfThisAPK( false, true );
		try {
			xmlResManage xmlEntry = null;
			
			for( ZipEntry zEntry = m_LIR_zIS.getNextEntry(); zEntry != null; zEntry = m_LIR_zIS.getNextEntry() ) {
				//__DEBUG__( "GetContentNext(): entry name = " + zEntry.getName() );
				//strA = zEntry.getName();
				__DEBUG__( "GetContentNext(): EntryName = " + strA );

				if( !foundPic && !foundText ) {
					xmlEntry = null;
					xmlEntry = XML_GetEntry( true );
				}

				//xmlResManage xmlEntry = XML_GetEntry( true );
				if( xmlEntry == null ) {
					__DEBUG_ERROR__( "GetContentNext(): " + "xmlEntry == NULL" );
					return;
				}
				else
					__DEBUG__( "GetContentNext(): " + "xmlEntry = \"" + xmlEntry.GetPics() + "\"" );

				if( foundPic == false && zEntry.getName().equals(xmlEntry.GetPics()) ) {
					byte data[] = new byte[MAX_BUF_SIZE];

					foundPic = true;
					m_LIR_baOS = new ByteArrayOutputStream();
					while( true ) {
						int count = m_LIR_zIS.read( data, 0, MAX_BUF_SIZE );
						if( count <= 0 ) break;
						
						//m_LIR_bOS.write( data, 0, count );
						m_LIR_baOS.write( data, 0, count );
					}
					
					__DEBUG__( "GetContentNext(): Zip Entry length = " + m_LIR_baOS.toByteArray().length );

					Bitmap bmp = BitmapFactory.decodeByteArray( /*zEntry.getExtra()*/m_LIR_baOS.toByteArray(), 0, /*zEntry.getExtra().length*/m_LIR_baOS.toByteArray().length );
					if( bmp != null ) {
						int w, h;
						android.view.ViewGroup.LayoutParams lp = iv.getLayoutParams();

						w = lp.width;
						h = lp.height;

						__DEBUG__( "GetContentNext(): Terminal width, height = " + w + ", " + h );
						if( w == -1 )
							w = getWindowManager().getDefaultDisplay().getWidth();

						iv.setImageBitmap( Bitmap.createScaledBitmap(bmp, w, h, true) );
						bmp.recycle();
					}
					
					m_currentImagePosition += 1;

					strA = xmlEntry.GetTitle();
					if( tv_title != null )
						tv_title.setText( strA );

					/*
					strA = "";
					strA = xmlEntry.GetText();
					if( tv_text != null )
						tv_text.setText( strA );

					break;
					*/
					
					TextView tv_textPosition = (TextView)findViewById( R.id.TextView_Position );
					if( tv_textPosition != null ) {
						String str = "(" + Integer.toString(GetCurrentPosition()) + "/" + Integer.toString(XML_GetEntryCount()) + ")";
						tv_textPosition.setText( str );
					}
					
					if( !foundText )
						continue;
				}

				if( !foundText ) {
					if( zEntry.getName().equals(xmlEntry.GetText()) ) {
						__DEBUG__( "GetContentNext(): found: " + zEntry.getName() );

						foundText = true;
						{
							byte[] bufReadBytesFile = new byte[MAX_BUF_SIZE_TEXT];
							File cacheDir = getCacheDir();
							String strFilename = "chapter_text";
							File tmpFile = File.createTempFile( strFilename, ".txt", cacheDir );
							OutputStream osOUT = new FileOutputStream( tmpFile );
							
							__DEBUG__( "GetContentNext(): Filename = " + tmpFile.getPath() );

							while( true ) {
								int count = m_LIR_zIS.read( bufReadBytesFile, 0, MAX_BUF_SIZE_TEXT );
								if( count <= 0 ) break;
								osOUT.write( bufReadBytesFile, 0, count );
							}

							osOUT.flush();
							osOUT.close();
					
							InputStreamReader isr = new InputStreamReader( GetInputStream(tmpFile) );
							BufferedReader br = new BufferedReader( isr );
							String strGetLine;
							StringBuilder sb = new StringBuilder();

							try {
								while( (strGetLine = br.readLine()) != null ){ 
									sb.append( strGetLine ); 
									sb.append( "\n" );
								}
								br.close();
								isr.close();
								
								if( tv_text != null )
									tv_text.setText( sb );
							}
							catch (IOException e) {
								// TODO Auto-generated catch block
								//e.printStackTrace();
								__DEBUG_ERROR__( "GetContentNext(): IOException: " + e.getMessage() );
								
								if( tmpFile != null ) {
									tmpFile.delete();
									tmpFile = null;
								}
								
								return;
							}
							
							if( tmpFile != null ) {
								tmpFile.delete();
								tmpFile = null;
							}
						}

						if( foundPic == true )
							break;
					}
				}
			}
			
			// Show the Blank Image if Image isn't available
			if( foundPic == false ) {
				foundPic = true;
				m_currentImagePosition += 1;

				strA = xmlEntry.GetTitle();
				if( tv_title != null )
					tv_title.setText( strA );

				TextView tv_textPosition = (TextView)findViewById( R.id.TextView_Position );
				if( tv_textPosition != null ) {
					String str = "(" + Integer.toString(GetCurrentPosition()) + "/" + Integer.toString(XML_GetEntryCount()) + ")";
					tv_textPosition.setText( str );
				}
				
				if( iv != null ) {
					iv.setImageResource( R.drawable.no_image_available );
				}
			}
			
			// Scroll To Top (0, 0)
			{
				android.widget.ScrollView sv = (android.widget.ScrollView)findViewById( R.id.ScrollView_TextBody );
				if( sv != null ) {
					sv.scrollTo( 0, 0 );
				}
			}
		}
		catch (IOException e) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
			__DEBUG_ERROR__( "GetContentNext(): Exception: " + e.getMessage() );
		}
	}

	public void GetContentMoveTo(int pos) {
		__DEBUG__( "GetContentMoveTo()" );
		
		int MAX_BUF_SIZE = 2048;
		int MAX_BUF_SIZE_TEXT = 1024;
		TextView tv_title = (TextView)findViewById( R.id.TextView_Title );
		TextView tv_text = (TextView)findViewById( R.id.TextView_Text );
		ImageView iv = (ImageView)findViewById( R.id.ImageView_Pics );
		String strA = "";
		boolean foundPic = false;
		boolean foundText = false;

		LoadFromResourceOfThisAPK( false, true );
		try {
			xmlResManage xmlEntry = null;
			
			for( ZipEntry zEntry = m_LIR_zIS.getNextEntry(); zEntry != null; zEntry = m_LIR_zIS.getNextEntry() ) {
				//__DEBUG__( "GetContentMoveTo(): entry name = " + zEntry.getName() );
				//strA = zEntry.getName();
				__DEBUG__( "GetContentMoveTo(): EntryName = " + strA );

				if( !foundPic && !foundText ) {
					xmlEntry = null;
					xmlEntry = XML_GetEntry( true );
				}

				//xmlResManage xmlEntry = XML_GetEntry( true );
				if( xmlEntry == null ) {
					__DEBUG_ERROR__( "GetContentMoveTo(): " + "xmlEntry == NULL" );
					return;
				}
				else
					__DEBUG__( "GetContentMoveTo(): " + "xmlEntry = \"" + xmlEntry.GetPics() + "\"" );

				if( foundPic == false && zEntry.getName().equals(xmlEntry.GetPics()) ) {
					byte data[] = new byte[MAX_BUF_SIZE];

					foundPic = true;
					m_LIR_baOS = new ByteArrayOutputStream();
					while( true ) {
						int count = m_LIR_zIS.read( data, 0, MAX_BUF_SIZE );
						if( count <= 0 ) break;
						
						//m_LIR_bOS.write( data, 0, count );
						m_LIR_baOS.write( data, 0, count );
					}
					
					__DEBUG__( "GetContentMoveTo(): Zip Entry length = " + m_LIR_baOS.toByteArray().length );

					Bitmap bmp = BitmapFactory.decodeByteArray( /*zEntry.getExtra()*/m_LIR_baOS.toByteArray(), 0, /*zEntry.getExtra().length*/m_LIR_baOS.toByteArray().length );
					if( bmp != null ) {
						int w, h;
						android.view.ViewGroup.LayoutParams lp = iv.getLayoutParams();

						w = lp.width;
						h = lp.height;

						__DEBUG__( "GetContentMoveTo(): Terminal width, height = " + w + ", " + h );
						if( w == -1 )
							w = getWindowManager().getDefaultDisplay().getWidth();

						iv.setImageBitmap( Bitmap.createScaledBitmap(bmp, w, h, true) );
						bmp.recycle();
					}
					
					//m_currentImagePosition += 1;

					strA = xmlEntry.GetTitle();
					if( tv_title != null )
						tv_title.setText( strA );

					/*
					strA = "";
					strA = xmlEntry.GetText();
					if( tv_text != null )
						tv_text.setText( strA );

					break;
					*/
					
					TextView tv_textPosition = (TextView)findViewById( R.id.TextView_Position );
					if( tv_textPosition != null ) {
						// NOTE: (GetCurrentPosition() + 1)
						String str = "(" + Integer.toString(GetCurrentPosition()+1) + "/" + Integer.toString(XML_GetEntryCount()) + ")";
						tv_textPosition.setText( str );
					}
					
					if( !foundText )
						continue;
				}

				if( !foundText ) {
					if( zEntry.getName().equals(xmlEntry.GetText()) ) {
						__DEBUG__( "GetContentMoveTo(): found: " + zEntry.getName() );

						foundText = true;
						{
							byte[] bufReadBytesFile = new byte[MAX_BUF_SIZE_TEXT];
							File cacheDir = getCacheDir();
							String strFilename = "chapter_text";
							File tmpFile = File.createTempFile( strFilename, ".txt", cacheDir );
							OutputStream osOUT = new FileOutputStream( tmpFile );
							
							__DEBUG__( "GetContentMoveTo(): Filename = " + tmpFile.getPath() );

							while( true ) {
								int count = m_LIR_zIS.read( bufReadBytesFile, 0, MAX_BUF_SIZE_TEXT );
								if( count <= 0 ) break;
								osOUT.write( bufReadBytesFile, 0, count );
							}

							osOUT.flush();
							osOUT.close();
					
							InputStreamReader isr = new InputStreamReader( GetInputStream(tmpFile) );
							BufferedReader br = new BufferedReader( isr );
							String strGetLine;
							StringBuilder sb = new StringBuilder();

							try {
								while( (strGetLine = br.readLine()) != null ){ 
									sb.append( strGetLine ); 
									sb.append( "\n" );
								}
								br.close();
								isr.close();
								
								if( tv_text != null )
									tv_text.setText( sb );
							}
							catch (IOException e) {
								// TODO Auto-generated catch block
								//e.printStackTrace();
								__DEBUG_ERROR__( "GetContentMoveTo(): IOException: " + e.getMessage() );
								
								if( tmpFile != null ) {
									tmpFile.delete();
									tmpFile = null;
								}
								
								return;
							}
							
							if( tmpFile != null ) {
								tmpFile.delete();
								tmpFile = null;
							}
						}

						if( foundPic == true )
							break;
					}
				}
			}
			
			// Show the Blank Image if Image isn't available
			if( foundPic == false ) {
				foundPic = true;
				//m_currentImagePosition += 1;

				strA = xmlEntry.GetTitle();
				if( tv_title != null )
					tv_title.setText( strA );

				TextView tv_textPosition = (TextView)findViewById( R.id.TextView_Position );
				if( tv_textPosition != null ) {
					// NOTE: (GetCurrentPosition() + 1)
					String str = "(" + Integer.toString(GetCurrentPosition()+1) + "/" + Integer.toString(XML_GetEntryCount()) + ")";
					tv_textPosition.setText( str );
				}
				
				if( iv != null ) {
					iv.setImageResource( R.drawable.no_image_available );
				}
			}
			
			// Scroll To Top (0, 0)
			{
				android.widget.ScrollView sv = (android.widget.ScrollView)findViewById( R.id.ScrollView_TextBody );
				if( sv != null ) {
					sv.scrollTo( 0, 0 );
				}
			}
			
			if( m_currentImagePosition >= XML_GetEntryCount() ) {
				ImageButton btn_next = (ImageButton)findViewById(R.id.Button_Next );
				ImageButton btn_prev = (ImageButton)findViewById(R.id.Button_Prev );

				if( btn_next != null )
					btn_next.setBackgroundResource( R.drawable.btn_arrow_next_empty );

				if( btn_prev != null )
					btn_prev.setBackgroundResource( R.drawable.btn_arrow_prev_thick );
			}
			else if( m_currentImagePosition <= 0 ) {
				ImageButton btn_next = (ImageButton)findViewById(R.id.Button_Next );
				ImageButton btn_prev = (ImageButton)findViewById(R.id.Button_Prev );

				if( btn_next != null )
					btn_next.setBackgroundResource( R.drawable.btn_arrow_next_thick );

				if( btn_prev != null )
					btn_prev.setBackgroundResource( R.drawable.btn_arrow_prev_empty );
			}
			
			m_currentImagePosition += 1;
		}
		catch (IOException e) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
			__DEBUG_ERROR__( "GetContentMoveTo(): Exception: " + e.getMessage() );
		}
	}
	
// -------------------------------------------
// Handling XML
// -------------------------------------------
	/*
	 * test.xml
		<? xml version="1.0" encoding="UTF-8" ?>
		<rss version="2.0">
		<contents>
			<chapter>
				<num> 1 </num>
				<title> title... </title>
				<pics> pic1.jpg </pics>
				<audio> a1.xxx </audio>
				<text> text1... </text>
			</chapter>
		</contents>
		</rss>

	 * result:
		=====START_DOCUMENT:
		RSS: rss
		RSS: contents
		RSS: chapter
		=====TEXT:
		=====START_TAG: num
		TEXT: 1
		TEXT: title...
		TEXT: pic1.jpg
		TEXT: a1.xxx
		TEXT: text1...
		strNum = 1
		strTitle = title...
		strPics = pic1.jpg
		strAudio = a1.xxx
		strText = text1...
		=====END_TAG: rss
	*/

// -------------------------------------------
// Get InputStream for XML From Resource of this APK
// -------------------------------------------
	private InputStream GetInputStreamFromResourceOfThisAPK(int resID) {
		__DEBUG__( "GetInputStreamFromResourceOfThisAPK()" );

		try {
			//AssetFileDescriptor afd = this.getResources().openRawResourceFd( resID );
			//InputStream is = afd.createInputStream();
			
			InputStream is = this.getResources().openRawResource( resID );
			return is;
		}
		catch( Exception e ) {
			__DEBUG_ERROR__( "GetInputStreamFromResourceOfThisAPK(): Exception: " + e.getMessage() );
		}
		
		return null;
	}

// -------------------------------------------
// Get InputStream for XML From URL
// -------------------------------------------
	private InputStream GetInputStreamFromURL(String strURL) {
		__DEBUG__( "GetInputStreamFromURL()" );

		while( true ) {
			try {
				URL url = new URL( strURL );
				URLConnection urlConnection = url.openConnection();
				InputStream is = urlConnection.getInputStream();
				return is;
			}
			catch( Exception e ) {
				__DEBUG_ERROR__( "GetInputStreamFromURL(): Exception: " + e.getMessage() );
			}
		}
	}

// -------------------------------------------
// XML Management Class
// NOTE: SEE xmlResManage.java
// -------------------------------------------
/*
	private class xmlResManage {
		private String m_strNum = "";
		private String m_strTitle = "";
		private String m_strPics = "";
		private String m_strAudio = "";
		private String m_strText = "";

		private void xmlResManage() {
			__DEBUG__( "class xmlResManage" );
		}
		public void SetNum(String strNum) { m_strNum = strNum; }
		public void SetTitle(String strTitle) { m_strTitle = strTitle; }
		public void SetPics(String strPics) { m_strPics = strPics; }
		public void SetAudio(String strAudio) { m_strAudio = strAudio; }
		public void SetText(String strText) { m_strText = strText; }
		
		public String GetNum() { return m_strNum; }
		public String GetTitle() { return m_strTitle; }
		public String GetPics() { return m_strPics; }
		public String GetAudio() { return m_strAudio; }
		public String GetText() { return m_strText; }
	}
*/

// -------------------------------------------
// Load XML Test
// -------------------------------------------
	// http://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html
	//private List<String> xmlTest() {
	private void XML_GetAll() {
		__DEBUG__( "XML_GetAll()" );

		//List<String> stringList = new ArrayList<String>();

		try {
			XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
			XmlPullParser xpp = null;
			InputStream stream = null;
			int eventType = 0;

			if( factory == null ) {
				__DEBUG_ERROR__( "XML_GetAll(): factory == NULL" );
				return;
			}

			factory.setNamespaceAware( true );
			xpp = factory.newPullParser();

			if( xpp == null ) {
				__DEBUG_ERROR__( "XML_GetAll(): xpp == NULL" );
				return;
			}

/*
			// Load XML from URL
			stream = GetInputStreamFromURL( "http://tvpot.daum.net/rss/RssBestDay.do?range=0&amp;type=2" );
			if( stream == null ) {
				__DEBUG_ERROR__( "XML_GetAll(): stream == NULL" );
				return;
			}
			xpp.setInput( stream, "UTF-8" );
*/

/*
String strXML = "<rss version=\"2.0\">";
strXML += "<contents>";
strXML += "		<chapter>";
strXML += "			<num> 1 </num>";
strXML += "			<title> title... </title>";
strXML += "			<pics> pic1.jpg </pics>";
strXML += "			<audio> a1.xxx </audio>";
strXML += "			<text> text1... </text>";
strXML += "		</chapter>";
strXML += "</contents>";
strXML += "</rss>";
			// Load XML from String
			xpp.setInput( new StringReader(strXML) );
*/

/*
			// Load XML from Resource of this APK
			stream = GetInputStreamFromResourceOfThisAPK( R.raw.text );
			if( stream == null ) {
				__DEBUG_ERROR__( "XML_GetAll(): stream == NULL" );
				return;
			}
			xpp.setInput( stream, "UTF-8" );
*/

			// Load XML from Resource(zip) of this APK
			stream = GetXmlStream();
			if( stream == null ) {
				__DEBUG_ERROR__( "XML_GetAll(): stream == NULL" );
				return;
			}
			xpp.setInput( stream, "UTF-8" );

			eventType = xpp.getEventType();
			while( eventType != XmlPullParser.END_DOCUMENT ) {
				switch( eventType ) {
					case XmlPullParser.START_DOCUMENT:
						//__DEBUG__( "=====START_DOCUMENT: " );
						break;
					case XmlPullParser.END_DOCUMENT:
						//__DEBUG__( "=====END_DOCUMENT: " );
						break;

					/*
					case XmlPullParser.START_TAG:
						__DEBUG__( "=====START_TAG: " + xpp.getName() );
						break;
					case XmlPullParser.END_TAG:
						__DEBUG__( "=====END_TAG: " + xpp.getName() );
						break;
					case XmlPullParser.TEXT:
						__DEBUG__( "=====TEXT: " + xpp.getText() );
						break; 
					*/

					case XmlPullParser.START_TAG:
						String strNum = "";
						String strTitle = "";
						String strPics = "";
						String strAudio = "";
						String strText = "";

						if( xpp.getName().equals("rss") ) {
							//__DEBUG__( "RSS: " + xpp.getName() );
							break;
						}
						if( xpp.getName().equals("contents") ) {
							//__DEBUG__( "RSS: " + xpp.getName() );
							break;
						}
						if( xpp.getName().equals("chapter") ) {
							//__DEBUG__( "RSS: " + xpp.getName() );
							break;
						}

						//__DEBUG__( "=====START_TAG: " + xpp.getName() );


						// <num>
						// Next: START_TAG TEXT
						eventType = xpp.next();
						strNum = xpp.getText();
						//__DEBUG__( "TEXT: " + strNum );
						// Next: END_TAG, END_TAG TEXT
						eventType = xpp.next();
						eventType = xpp.next();

						// <title>
						// Next: START_TAG, START_TAG TEXT
						eventType = xpp.next();
						eventType = xpp.next();
						strTitle = xpp.getText();
						//__DEBUG__( "TEXT: " + strTitle );
						// Next: END_TAG, END_TAG TEXT
						eventType = xpp.next();
						eventType = xpp.next();

						// <pics>
						// Next: START_TAG, START_TAG TEXT
						eventType = xpp.next();
						eventType = xpp.next();
						strPics = xpp.getText();
						//__DEBUG__( "TEXT: " + strPics );
						// Next: END_TAG, END_TAG TEXT
						eventType = xpp.next();
						eventType = xpp.next();

						// <audio>
						// Next: START_TAG, START_TAG TEXT
						eventType = xpp.next();
						eventType = xpp.next();
						strAudio = xpp.getText();
						//__DEBUG__( "TEXT: " + strAudio );
						// Next: END_TAG, END_TAG TEXT
						eventType = xpp.next();
						eventType = xpp.next();

						// <text>
						// Next: START_TAG, START_TAG TEXT
						eventType = xpp.next();
						eventType = xpp.next();
						strText = xpp.getText();
						//__DEBUG__( "TEXT: " + strText );
						// Next: END_TAG, END_TAG TEXT
						eventType = xpp.next();
						eventType = xpp.next();

						//__DEBUG__( "strNum = " + strNum + "\n" + "strTitle = " + strTitle + "\n" + "strPics = " + strPics + "\n" + "strAudio = " + strAudio + "\n" + "strText = " + strText );

						// Get Text
						//stringList.add( strNum, strTitle, strPics, strAudio, strText );
						xmlResManage xmlRes = new xmlResManage();
							xmlRes.SetNum( strNum );
							xmlRes.SetTitle( strTitle );
							xmlRes.SetPics( strPics );
							xmlRes.SetAudio( strAudio );
							xmlRes.SetText( strText );
						m_xmlResList.add( xmlRes );

						break;
					case XmlPullParser.END_TAG:
						//__DEBUG__( "=====END_TAG: " + xpp.getName() );
						break;
					case XmlPullParser.TEXT:
						//__DEBUG__( "=====TEXT: " + xpp.getText() );
						break; 
				}

				eventType = xpp.next();
			}

			if( stream != null ) {
				stream.close();
				stream = null;
			}
			
			factory = null;
			xpp = null;

			//return stringList;
		}
		catch( Exception e ) {
			__DEBUG_ERROR__( "=====: Exception: " + e.getMessage() );
			//return null;
		}
	}

// -------------------------------------------
// XML: GetEntryName
// -------------------------------------------
	public int XML_GetEntryCount() {
		__DEBUG__( "XML_GetEntryCount()" );
		
		int entryCnt = 0;
	
		if( m_xmlResList == null ) {
			__DEBUG_ERROR__( "XML_GetEntryCount(): XML Resource List == NULL" );
			return entryCnt; 
		}

		if( m_xmlResList.isEmpty() ) {
			__DEBUG_ERROR__( "XML_GetEntryCount(): XML Resource List has an Empty" );
			return entryCnt;
		}

		entryCnt = m_xmlResList.size() - 1 ;
		__DEBUG__( "XML_GetEntryCount(): Entry Size = " + entryCnt );
		
		return entryCnt;
	}

	public xmlResManage XML_GetEntry(boolean isNext) {
		__DEBUG__( "XML_GetEntry()" );

		xmlResManage ret = null;
		int pos = -1;
		int entryCnt = 0;

		if( m_xmlResList == null ) {
			__DEBUG_ERROR__( "XML_GetEntry(): XML Resource List == NULL" );
			return null; 
		}

		if( m_xmlResList.isEmpty() ) {
			__DEBUG_ERROR__( "XML_GetEntry(): XML Resource List has an Empty" );
			return null;
		}

		entryCnt = m_xmlResList.size() - 1 ;
		__DEBUG__( "XML_GetEntry(): Entry Size = " + entryCnt );

		// Next
		if( isNext ) {
			int tmpPos = (m_currentImagePosition + 1);
			if( tmpPos <= entryCnt )
				pos = m_currentImagePosition + 1;
			else {
				__DEBUG__( "XML_GetEntry(): END" );
				return null;
			}
			
			// Next/Prev button highlight
			if( pos > 0 ) {
				ImageButton btn_prev = (ImageButton)findViewById(R.id.Button_Prev );
				if( btn_prev != null )
					btn_prev.setBackgroundResource( R.drawable.btn_arrow_prev_thick );
			}
			if( pos >= entryCnt ) {
				ImageButton btn_next = (ImageButton)findViewById(R.id.Button_Next );
				ImageButton btn_prev = (ImageButton)findViewById(R.id.Button_Prev );

				if( btn_next != null )
					btn_next.setBackgroundResource( R.drawable.btn_arrow_next_empty );

				if( btn_prev != null )
					btn_prev.setBackgroundResource( R.drawable.btn_arrow_prev_thick );
			}
		}
		// Previous
		else {
			int tmpPos = (m_currentImagePosition - 1);
			if( (tmpPos >= 0) && (tmpPos <= entryCnt) )
				pos = m_currentImagePosition - 1;
			else {
				__DEBUG__( "XML_GetEntry(): FIRST" );
				return null;
			}
			
			// Next/Prev button highlight
			if( pos > 0 ) {
				ImageButton btn_next = (ImageButton)findViewById(R.id.Button_Next );
				if( btn_next != null )
					btn_next.setBackgroundResource( R.drawable.btn_arrow_next_thick );
			}
			if( pos <= 0 ) {
				ImageButton btn_next = (ImageButton)findViewById(R.id.Button_Next );
				ImageButton btn_prev = (ImageButton)findViewById(R.id.Button_Prev );

				if( btn_next != null )
					btn_next.setBackgroundResource( R.drawable.btn_arrow_next_thick );

				if( btn_prev != null )
					btn_prev.setBackgroundResource( R.drawable.btn_arrow_prev_empty );
			}
		}

		if( pos < 0 ) {
			__DEBUG_ERROR__( "XML_GetEntry(): Unknown Error" );
			return null;
		}

		__DEBUG__( "XML_GetEntry(): Entry Size = " + entryCnt + ", Pos = " + pos );
		ret = m_xmlResList.get( pos );

		return ret;
	}



// -------------------------------------------
// Main
// -------------------------------------------
	public void LoadContentsFromSDcard(String strFilename) {
		__DEBUG__( "LoadContentsFromSDcard()" );
		
		if( strFilename == null || strFilename.equals("") ) {
			__DEBUG__( "LoadContentsFromSDcard(): Cannot load a resource file" + "\"" + strFilename + "\"" );
        	Toast.makeText( ListenMyStory.this, "Cannot load a resource file" + "\"" + strFilename + "\"", Toast.LENGTH_SHORT ).show();
			return;
		}

        // Initialize
        //InitAll();

		// Zip File System
		LoadFromResourceOfSDcard( true, strFilename );
        if( !GetContentInit() ) {
        	__DEBUG__( "LoadContentsFromSDcard(): Cannot init content (XML)" );
        	Toast.makeText( ListenMyStory.this, "Cannot init content (XML)", Toast.LENGTH_SHORT ).show();
        	//finish();
        	return;
        }

		// XML
		XML_GetAll();
		
		// Get All of the Contents
		GetMainAllContents();
	}

	public void LoadContentsFromResource() {
		__DEBUG__( "LoadContentsFromResource()" );

        // Initialize
        //InitAll();

		// Zip File System
        LoadFromResourceOfThisAPK( true, false );
        if( !GetContentInit() ) {
        	__DEBUG__( "LoadContentsFromResource(): Cannot init content (XML)" );
        	Toast.makeText( ListenMyStory.this, "Cannot init content (XML)", Toast.LENGTH_SHORT ).show();
        	finish();
        	//return;
        }

		// XML
		XML_GetAll();
		
		// Get All of the Contents
		GetMainAllContents();
	}

	public void GetMainAllContents() {
		__DEBUG__( "GetMainAllContents()" );

		// Set first page
		if( m_xmlResList != null && !m_xmlResList.isEmpty() ) {
			if( m_xmlResManage != null ) {
				xmlResManage xmlEntry = m_xmlResList.get( 0 );

				if( xmlEntry != null ) {
					TextView tv_title = (TextView)findViewById( R.id.TextView_Title );
					TextView tv_text = (TextView)findViewById( R.id.TextView_Text );
					TextView tv_textPosition = (TextView)findViewById( R.id.TextView_Position );
					
					if( tv_title != null )
						tv_title.setText( xmlEntry.GetTitle() );

					//if( tv_text != null )
					//	tv_text.setText( xmlEntry.GetText() );

					if( tv_textPosition != null ) {
						String str = "(" + Integer.toString(GetCurrentPosition()) + "/" + Integer.toString(XML_GetEntryCount()) + ")";
						tv_textPosition.setText( str );
					}
				}
				
				// Set Xml list to Main Class of the Application
				m_MainApp.SetXmlResManage( m_xmlResList );
			}
		}
		else {
        	__DEBUG__( "GetMainAllContents(): Could not init first content" );
        	Toast.makeText( ListenMyStory.this, "Could not init first content", Toast.LENGTH_SHORT ).show();
			finish();
			//return;
		}
		
		{
			int entryCnt = m_xmlResList.size() - 1 ;

			// Next/Prev button highlight
			if( entryCnt <= 0) {
				ImageButton btn_next = (ImageButton)findViewById(R.id.Button_Next );
				ImageButton btn_prev = (ImageButton)findViewById(R.id.Button_Prev );

				if( btn_next != null )
					btn_next.setBackgroundResource( R.drawable.btn_arrow_next_empty );

				if( btn_prev != null )
					btn_prev.setBackgroundResource( R.drawable.btn_arrow_prev_empty );
			}
			else {
				ImageButton btn_next = (ImageButton)findViewById(R.id.Button_Next );
				ImageButton btn_prev = (ImageButton)findViewById(R.id.Button_Prev );

				if( btn_next != null )
					btn_next.setBackgroundResource( R.drawable.btn_arrow_next_thick );

				if( btn_prev != null )
					btn_prev.setBackgroundResource( R.drawable.btn_arrow_prev_empty );
			}
		}
	}



// -------------------------------------------
// TEST
// -------------------------------------------
    public void TEST_ZipArchive() {
    	__DEBUG__( "TEST_ZipArchive()" );

		AssetFileDescriptor afd = getResources().openRawResourceFd( m_ResPackage );
		InputStream is = null;
		OutputStream os = null;
		//BufferedOutputStream bOS = null;
		ByteArrayOutputStream baOS = null;

		int MAX_BUF_SIZE = 2048;
		TextView tv = (TextView)findViewById( R.id.TextView_Text );
		ImageView iv = (ImageView)findViewById( R.id.ImageView_Pics );
		String strA = "";

		try {
			is = afd.createInputStream();
			ZipInputStream zIS = new ZipInputStream( is );
			ZipOutputStream zOS = null;

			for( ZipEntry zEntry = zIS.getNextEntry(); zEntry != null; zEntry = zIS.getNextEntry() ) {
				//__DEBUG__( "zzz(): entry name = " + zEntry.getName() );
				strA += zEntry.getName() + ", ";
				
				if( zEntry.getName().equals( "a1.jpg") ) {
					byte data[] = new byte[MAX_BUF_SIZE];
					//os = new FileOutputStream( zEntry.getName() );
					//bOS = new BufferedOutputStream( os, MAX_BUF_SIZE );

					baOS = new ByteArrayOutputStream();
					while( true ) {
						int count = zIS.read( data, 0, MAX_BUF_SIZE );
						if( count <= 0 ) break;
						
						//bOS.write( data, 0, count );
						baOS.write( data, 0, count );
					}
					
					__DEBUG__( "TEST_ZipArchive(): entry length = " + baOS.toByteArray().length );

					//Bitmap bmp = BitmapFactory.decodeByteArray( zEntry.getExtra(), 0, zEntry.getExtra().length );
					Bitmap bmp = BitmapFactory.decodeByteArray( /*zEntry.getExtra()*/baOS.toByteArray(), 0, /*zEntry.getExtra().length*/baOS.toByteArray().length );
					if( bmp != null ) {
						int w, h;
						android.view.ViewGroup.LayoutParams lp = iv.getLayoutParams();

						w = lp.width;
						h = lp.height;

						__DEBUG__( "TEST_ZipArchive(): width, height = " + w + ", " + h );
						if( w == -1 )
							w = getWindowManager().getDefaultDisplay().getWidth();

						iv.setImageBitmap( Bitmap.createScaledBitmap(bmp, w, h, true) );
						bmp.recycle();
					}
				}
			}
			
			tv.setText( strA );

			baOS.close();
			zIS.close();
			afd.close();
			is.close();

			baOS = null;
			zIS = null;
			afd = null;
			is = null;
		}
		catch( IOException e ) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
			__DEBUG_ERROR__( "TEST_ZipArchive(): IOException: " + e.getMessage() );
		}
		catch( Exception e ) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
			__DEBUG_ERROR__( "TEST_ZipArchive(): Exception: " + e.getMessage() );
		}
    }

	public void TEST_GetContent() {
		__DEBUG__( "TEST_GetContent()" );
		
		int MAX_BUF_SIZE = 2048;
		TextView tv = (TextView)findViewById( R.id.TextView_Text );
		ImageView iv = (ImageView)findViewById( R.id.ImageView_Pics );
		String strA = "";

		try {
			for( ZipEntry zEntry = m_LIR_zIS.getNextEntry(); zEntry != null; zEntry = m_LIR_zIS.getNextEntry() ) {
				//__DEBUG__( "TEST_GetContent(): entry name = " + zEntry.getName() );
				strA = zEntry.getName() + ", ";
				
				//if( zEntry.getName().equals( "gallery_photo_1.jpg") ) {
				if( zEntry.getName().contains(".jpg") ) {
					byte data[] = new byte[MAX_BUF_SIZE];

					m_LIR_baOS = new ByteArrayOutputStream();
					while( true ) {
						int count = m_LIR_zIS.read( data, 0, MAX_BUF_SIZE );
						if( count <= 0 ) break;
						
						//m_LIR_bOS.write( data, 0, count );
						m_LIR_baOS.write( data, 0, count );
					}
					
					__DEBUG__( "TEST_GetContent(): Zip Entry length = " + m_LIR_baOS.toByteArray().length );

					Bitmap bmp = BitmapFactory.decodeByteArray( /*zEntry.getExtra()*/m_LIR_baOS.toByteArray(), 0, /*zEntry.getExtra().length*/m_LIR_baOS.toByteArray().length );
					if( bmp != null ) {
						int w, h;
						android.view.ViewGroup.LayoutParams lp = iv.getLayoutParams();

						w = lp.width;
						h = lp.height;

						__DEBUG__( "TEST_GetContent(): Terminal width, height = " + w + ", " + h );
						if( w == -1 )
							w = getWindowManager().getDefaultDisplay().getWidth();

						iv.setImageBitmap( Bitmap.createScaledBitmap(bmp, w, h, true) );
						bmp.recycle();
					}
					
					//m_currentImagePosition += 1;
					tv.setText( strA );
					break;
				}
			}
		}
		catch (IOException e) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
			__DEBUG_ERROR__( "TEST_GetContent(): Exception: " + e.getMessage() );
		}
	}

	public void TEST_XML_Array() {
		__DEBUG__( "TEST_XML_Array()" );
		
		if( m_xmlResList == null ) {
			__DEBUG_ERROR__( "TEST_XML_Array(): XML Resource List == NULL" );
			return; 
		}

		if( m_xmlResList.isEmpty() ) {
			__DEBUG_ERROR__( "TEST_XML_Array(): XML Resource List has an Empty" );
			return;
		}
		
		Iterator iter = m_xmlResList.iterator();
		while( iter.hasNext() ) {
			xmlResManage xmlRes = (xmlResManage)iter.next();

			if( xmlRes != null ) {
				__DEBUG__( "----------------------------" );
				__DEBUG__( "strNum = \"" + xmlRes.GetNum() + "\"" );
				__DEBUG__( "strTitle = \"" + xmlRes.GetTitle() + "\"" );
				__DEBUG__( "strPics = \"" + xmlRes.GetPics() + "\"" );
				__DEBUG__( "strAudio = \"" + xmlRes.GetAudio() + "\"" );
				__DEBUG__( "strText = \"" + xmlRes.GetText() + "\"" );

				xmlRes = null;
			}
		}

		__DEBUG__( "----------------------------" );
	}
}



//-------------------------------------------
// __EOF__
//-------------------------------------------
